﻿---@diagnostic disable: trailing-space
local extension = Package:new("moepack_moesp")
extension.extensionName = "moepack"

Fk:loadTranslationTable{
  ["moepack_moesp"] = "萌包-SP",
  ["moesp"] = "萌SP",
}

local U = require "packages/utility/utility"

local MoeFunc = require "packages/moepack/moepack_function"

local moesp__emoprincess = General(extension, "moesp__emoprincess", "moe", 3, 3, General.Female)

local emo__jiqi = fk.CreateTriggerSkill{
  name = "emo__jiqi",
  anim_type = "control",
  events = {fk.EventPhaseEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target.phase > 1 and target.phase < 8 then
      local list = {}
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.from and move.from == player.id then
            for _, info in ipairs(move.moveInfo) do
              if info.fromArea == Card.PlayerHand then
                local card = Fk:getCardById(info.cardId)
                if card.type == Card.TypeBasic and card.color ~= Card.NoColor then
                  table.insertIfNeed(list, card.color == Card.Black and "trick" or "equip")
                end
              end
            end
          end
        end
        return #list == 2
      end, Player.HistoryPhase)
      if #list > 0 then
        self.cost_data = list
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local list = self.cost_data
    if player.dead then return end

    local ids = {}
    for _, name in ipairs(list) do
      local c = room:getCardsFromPileByRule(".|.|.|.|.|"..name)
      if #c > 0 then
        table.insert(ids, c[1])
      end
    end
    if #ids == 0 then return false end
    room:moveCards({
      ids = ids,
      fromArea = Card.DrawPile,
      to = player.id,
      toArea = Card.PlayerHand,
      moveReason = fk.ReasonPrey,
      skillName = self.name,
      moveVisible = false,
    })
    
    while #ids > 0 do
      ids = table.filter(ids, function (cid) return room:getCardArea(cid) == Card.PlayerHand and room:getCardOwner(cid) == player end)
      local use = U.askForUseRealCard(room, player, ids, ".", self.name, "#emo__jiqi-use", {bypass_times=true})
      if not use then break end
      table.removeOne(ids, use.card.id)
    end

    ids = table.filter(ids, function (cid) return room:getCardArea(cid) == Card.PlayerHand and room:getCardOwner(cid) == player end)
    if #ids > 0 then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__jiqi-give", self.name, true)
      if #tos > 0 then
        room:obtainCard(tos[1], ids, false, fk.ReasonGive, player.id, self.name)
      else
        room:throwCard(ids, self.name, player, player)
      end
    end
  end,
}

moesp__emoprincess:addSkill(emo__jiqi)

local emo__zhisi = fk.CreateTriggerSkill{
  name = "emo__zhisi",
  anim_type = "drawcard",
  events = {fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_cost = function (self, event, target, player, data)
    local choice = player.room:askForChoice(player, {"emo__zhisi_haven", "emo__zhisi_nohaven", "cancel"}, self.name)
    if choice ~= "cancel" then
      self.cost_data = choice
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local choice = self.cost_data
    local all = {"spade","club","heart","diamond","nosuit"}
    local suits = {}
    for _, suit in ipairs(all) do
      if table.find(player:getCardIds("h"), function (id)
        return Fk:getCardById(id):getSuitString() == suit
      end) then
        table.insert(suits, suit)
      end
    end
    if choice == "emo__zhisi_nohaven" then 
      suits = table.filter(all ,function (s) return not table.contains(suits, s) end)
    end

    local cards = {}
    for _, suit in ipairs(suits) do
      local ids = room:getCardsFromPileByRule(".|.|"..suit)
      if #ids > 0 then table.insert(cards, ids[1]) end
    end
    if #cards > 0 then
      room:moveCards({
        ids = cards,
        fromArea = Card.DrawPile,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonDraw,
        skillName = self.name,
        moveVisible = false,})
    end
  end,
}
moesp__emoprincess:addSkill(emo__zhisi)


Fk:loadTranslationTable{
  ["moesp__emoprincess"] = "忆默公主",

  ["emo__jiqi"] = "集奇",
  [":emo__jiqi"] = "任何阶段结束时，若你本阶段失去了黑色/红色基本牌，你可以摸一张锦囊牌/装备牌，然后你可以使用这些牌，未使用的牌须交给一名其他角色或弃置之。",
  ["#emo__jiqi-use"] = "集奇：你可以使用这些牌",
  ["#emo__jiqi-give"] = "集奇：将这些牌交给一名其他角色角色。点“取消”：弃置之",

  ["emo__zhisi"] = "智思",
  [":emo__zhisi"] = "每当你受到伤害后，你可以摸手牌中已有或未有的花色各一张牌。",
  ["emo__zhisi_haven"] = "摸已有花色",
  ["emo__zhisi_nohaven"] = "摸未有花色",
}

local moesp__qi = General(extension, "moesp__qi", "moe", 3, 7, General.Female)

local emo__fuyuan = fk.CreateTriggerSkill{
  name = "emo__fuyuan",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(1, self.name)
    if player.dead or player:isKongcheng() then return end
    local cards = player:getCardIds("h")
    player:showCards(cards)
    if table.find(cards, function(id) return Fk:getCardById(id).name == "jink" end) then
      local targets = room:askForChooseToMoveCardInBoard(player, "#emo__fuyuan-move", self.name, true)
      if #targets > 1 then
        targets = table.map(targets, Util.Id2PlayerMapper)
        room:askForMoveCardInBoard(player, targets[1], targets[2], self.name)
      end
    else
      if data.from and not data.from.dead and not data.from:isNude() then
        room:askForDiscard(data.from, 2, 2, true, self.name, false)
      end
    end
  end,
}
moesp__qi:addSkill(emo__fuyuan)

-- 根据关键词获得技能
local doJiren = function (player, event)
  local room = player.room
  if player.dead then return end
  room:changeMaxHp(player, -1)
  if player.dead then return end
  local skillName = "emo__jiren"
  local skillPatterns = {
    [fk.Damage] = "军兵战武锋援阵",[fk.Deathed] = "讨伐追袭击诛仇",[fk.AfterCardsMove] = "清德守节奋义力",
    [fk.CardUseFinished] = "政策决势谏言才",[fk.EnterDying] = "宠虚抚蛮绝离乱",[fk.RoundStart] = "神龙天命心破烈"
  }
  local pattern = skillPatterns[event]
  local str = {}
  for i = 1, pattern:len() do
    local s = pattern[i]
    table.insert(str, s)
  end
  local skills = {}
  for _, general_name in pairs(room.general_pile) do
    local general = Fk.generals[general_name]
    for _, skill_name in ipairs(general:getSkillNameList()) do
      local skill = Fk.skills[skill_name]
      if not player:hasSkill(skill,true) and table.find(str, function(s) return string.find(Fk:translate(skill.name), s) end)
      and skill.frequency < 5 and (#skill.attachedKingdom == 0 or table.contains(skill.attachedKingdom, player.kingdom)) then
        table.insert(skills, skill.name)
      end
    end
  end
  if #skills == 0 then return end
  local choice = room:askForChoice(player, table.random(skills, 3), skillName, nil, true)
  room:handleAddLoseSkills(player, choice)
end

local function updataJirenMark(player)
  local room = player.room
  local mark = {}
  local removed = player:getTableMark("emo__jiren_removed")
  for i = 1, 6 do
    local m = "emo__jiren_"..i
    if not table.contains(removed, m) then
      table.insert(mark, m)
    end
  end
  room:setPlayerMark(player, "@[:]emo__jiren", #mark > 0 and mark or 0)
end

local emo__jiren = fk.CreateTriggerSkill{
  name = "emo__jiren",
  frequency = Skill.Compulsory,
  events = {fk.Damage, fk.Deathed, fk.AfterCardsMove, fk.CardUseFinished, fk.EnterDying, fk.RoundStart},
  can_trigger = function (self, event, target, player, data)
    local room = player.room
    if not player:hasSkill(self) then return false end
    local event_list = {fk.Damage, fk.Deathed, fk.AfterCardsMove, fk.CardUseFinished, fk.EnterDying, fk.RoundStart}
    local choice = "emo__jiren_"..table.indexOf(event_list, event)
    if table.contains(player:getTableMark("emo__jiren_removed"), choice) then return false end
    if event == fk.Damage then
      return player == target and not data.to.dead
    elseif event == fk.Deathed then
      return data.damage and data.damage.from and data.damage.from == player
    elseif event == fk.AfterCardsMove then
      if #room:getOtherPlayers(player) == 0 then return false end
      local ids = {}
      for _, move in ipairs(data) do
        if move.from == player.id and move.moveReason == fk.ReasonDiscard then
          for _, info in ipairs(move.moveInfo) do
            if Fk:getCardById(info.cardId).type == Card.TypeEquip and room:getCardArea(info.cardId) == Card.DiscardPile then
              table.insert(ids, info.cardId)
            end
          end
        end
      end
      if #ids > 0 then
        self.cost_data = ids
        return true
      end
    elseif event == fk.CardUseFinished then
      return player == target and data.card:isCommonTrick() and (not data.card:isVirtual() or #data.card.subcards > 0)
      and Fk:translate(data.card.name):len() == 4 and player.room:getCardArea(data.card) == Card.Processing
    elseif event == fk.EnterDying then
      return player == target
    elseif event == fk.RoundStart then
      return room:getTag("RoundCount") == 6
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local event_list = {fk.Damage, fk.Deathed, fk.AfterCardsMove, fk.CardUseFinished, fk.EnterDying, fk.RoundStart}
    local choice = "emo__jiren_"..table.indexOf(event_list, event)
    room:addTableMark(player, "emo__jiren_removed", choice)
    updataJirenMark(player)
    if event == fk.Damage then
      room:damage { from = player, to = data.to, damage = 1, skillName = self.name }
    elseif event == fk.Deathed then
      player:drawCards(3, self.name)
    elseif event == fk.AfterCardsMove then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__jiren-equip", self.name, false)
      local to = room:getPlayerById(tos[1])
      room:moveCardTo(self.cost_data, Card.PlayerHand, to, fk.ReasonGive, self.name, nil, true, player.id)
    elseif event == fk.CardUseFinished then
      room:obtainCard(player, data.card, true, fk.ReasonPrey)
    elseif event == fk.EnterDying then
      if player:isWounded() then
        room:recover { num = 1, skillName = self.name, who = player , recoverBy = player}
      end
    elseif event == fk.RoundStart then
      for _, cid in ipairs(room.draw_pile) do
        local card = Fk:getCardById(cid)
        if card.type == Card.TypeEquip and player:canUse(card) and not player:prohibitUse(card) then
          room:useCard({ from = player.id, tos = {{player.id}}, card = card })
          break
        end
      end
    end
    doJiren (player, event)
  end,

  on_acquire = function (self, player)
    updataJirenMark(player)
  end,
  on_lose = function (self, player)
    player.room:setPlayerMark(player, "@[:]emo__jiren", 0)
  end,
}
moesp__qi:addSkill(emo__jiren)

Fk:loadTranslationTable{
  ["moesp__qi"] = "祈",

  ["emo__fuyuan"] = "福愿",
  [":emo__fuyuan"] = "每当你受到伤害后，你可以摸一张牌并展示所有手牌，若其中有【闪】，你可以移动场上一张牌，若无，你令来源弃置两张牌。",
  ["#emo__fuyuan-move"] = "福愿：你可以移动场上一张牌",

  ["emo__jiren"] = "己任",
  [":emo__jiren"] = "锁定技，每项限一次，以下时机你执行对应效果，然后扣减一体力上限并从包含关键字的三个技能中获得一个。"..
  "<br>①对一名角色造成伤害后，对其造成一点伤害，获得“军兵战武锋援阵”；"..
  "<br>②击杀一名角色后，摸三张牌，获得“讨伐追袭击诛仇”；"..
  "<br>③装备牌被弃置时，交给一名其他角色，获得“清德守节奋义力”；"..
  "<br>④使用非虚拟四字普通锦囊后，获得此牌，获得“政策决势谏言才”；"..
  "<br>⑤进入濒死状态时，回复一点体力，获得“宠虚抚蛮绝离乱”；"..
  "<br>⑥第六轮开始时，随机使用牌堆一张装备牌，获得“神龙天命心破烈”。",

  ["#emo__jiren-equip"] = "己任：将你弃置的装备牌交给一名其他角色",
  ["#emo__jiren-skill"] = "己任：选择一个技能获得",
  ["@[:]emo__jiren"] = "己任",
  ["emo__jiren_1"] = "造伤",
  [":emo__jiren_1"] = "①对一名角色造成伤害后，对其造成一点伤害，获得“军兵战武锋援阵”",
  ["emo__jiren_2"] = "击杀",
  [":emo__jiren_2"] = "②击杀一名角色后，摸三张牌，获得“讨伐追袭击诛仇”",
  ["emo__jiren_3"] = "装备",
  [":emo__jiren_3"] = "③装备牌被弃置时，交给一名其他角色，获得“清德守节奋义力”",
  ["emo__jiren_4"] = "锦囊",
  [":emo__jiren_4"] = "④使用非虚拟四字普通锦囊后，获得此牌，获得“政策决势谏言才”",
  ["emo__jiren_5"] = "濒死",
  [":emo__jiren_5"] = "⑤进入濒死状态时，回复一点体力，获得“宠虚抚蛮绝离乱”",
  ["emo__jiren_6"] = "六轮",
  [":emo__jiren_6"] = "⑥第六轮开始时，随机使用牌堆一张装备牌，获得“神龙天命心破烈”",
}

local moesp__quanzi = General(extension, "moesp__quanzi", "moe", 4, 4, General.Female)

local emo__shuangsheng = fk.CreateTriggerSkill{
  name = "emo__shuangsheng",
  anim_type = "drawcard",
  switch_skill_name = "emo__shuangsheng",
  events = {fk.Damaged , fk.Damage },
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and (player:getSwitchSkillState(self.name) == fk.SwitchYin or not player:isNude())
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local x = player:getLostHp() + 1
    if player:getSwitchSkillState(self.name) == fk.SwitchYang then
      local cards = room:askForCard(player, 1, x, true, self.name, true, ".", "#emo__shuangsheng-yang:::"..x)
      if #cards > 0 then
        self.cost_data = cards
        return true
      end
    else
      if room:askForSkillInvoke(player, self.name, nil, "#emo__shuangsheng-yin:::"..x) then
        self.cost_data = nil
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = self.cost_data
    if cards then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__shuangsheng-give", self.name, false)
      local to = room:getPlayerById(tos[1])
      room:obtainCard(to, cards, false, fk.ReasonGive)
      player:drawCards(#cards, self.name)
    else
      local x = player:getLostHp() + 1
      player:drawCards(x, self.name)
      local y = player:getHandcardNum() - player.maxHp
      if y > 0 then
        room:askForDiscard(player, y, y, false, self.name, false)
      end
      room:addPlayerMark(player, "@emo__shuangsheng_damage-turn")
    end
  end,
}

local emo__shuangsheng_damage = fk.CreateTriggerSkill{
  name = "#emo__shuangsheng_damage",
  anim_type = "defensive",
  events = {fk.DamageInflicted },
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:getMark("@emo__shuangsheng_damage-turn") > 0
  end,
  on_cost = function(self, event, target, player, data)
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player:getMark("@emo__shuangsheng_damage-turn")
    data.damage = data.damage - x
    return data.damage <= 0
  end,
}

emo__shuangsheng:addRelatedSkill(emo__shuangsheng_damage)

moesp__quanzi:addSkill(emo__shuangsheng)


local emo__jiyu = fk.CreateTriggerSkill{
  name = "emo__jiyu",
  anim_type = "control",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    local to
    local list = {}
    if player:hasSkill(self) then
      for _, move in ipairs(data) do
        if move.from == player.id and move.to and move.to ~= player.id then
          to = player.room:getPlayerById(move.to)
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerEquip or info.fromArea == Card.PlayerHand then
              local card = Fk:getCardById(info.cardId)
              if card.color ~= Card.NoColor then
                table.insertIfNeed(list, card:getColorString())
              end
            end
          end
        end
      end
    end
    if to then
      for _, n in ipairs(list) do
        self.cost_data = {to, n}
        self:doCost(event, target, player, data)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local to = self.cost_data[1]
    local n = self.cost_data[2]
    if n == "red" then
      return room:askForSkillInvoke(to, self.name, data, "#emo__jiyu-recover:"..player.id)
    else
      local use = room:askForUseCard(player, "slash", "slash", "#emo__jiyu-slash:"..to.id, true, {must_targets = {to.id},bypass_distances=true})
      if use then
        self.cost_data[3] = use
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = self.cost_data[1]
    local n = self.cost_data[2]
    if n == "red" then
      room:recover { num = 1, skillName = self.name, who = player , recoverBy = to}
    else
      local use = self.cost_data[3]
      room:useCard(use)
      if not to.dead then
        room:recover { num = 1, skillName = self.name, who = to , recoverBy = player}
      end
    end
  end,
}


moesp__quanzi:addSkill(emo__jiyu)

Fk:loadTranslationTable{
  ["moesp__quanzi"] = "权子", -- by 诺羽
  ["designer:moesp__quanzi"] = "诺羽",

  ["emo__shuangsheng"] = "双生",
  [":emo__shuangsheng"] = "转换技，当你造成或受到伤害后，阳：你可以交给一名其他角色至多X张牌，然后摸等量的牌。阴：你可以摸X张牌再弃置至体力上限，然后本回合你受到的伤害减一（X为你已损失体力值+1）。",
  ["#emo__shuangsheng-yang"] = "双生（阳）：可选择至多%arg张牌，交给一名其他角色",
  ["#emo__shuangsheng-give"] = "将这些牌交给一名其他角色，然后你摸等量的牌",
  ["@emo__shuangsheng_damage-turn"] = "双生减伤",
  ["#emo__shuangsheng_damage"] = "双生",
  ["#emo__shuangsheng-yin"] = "双生（阴）：可以摸%arg张牌再弃置至体力上限，本回合你受到的伤害减一",

  ["emo__jiyu"] = "寄寓",
  [":emo__jiyu"] = "当其他角色获得你的牌后，若其中有红色牌，其可以令你回复一点体力，若其中有黑色牌，你可以对其使用一张【杀】，若其存活则你令其回复一点体力。",
  ["#emo__jiyu-recover"] = "寄寓：你可令%src回复一点体力",
  ["#emo__jiyu-slash"] = "寄寓：你可以对%src使用一张【杀】，再令其回复一点体力",
}

local moesp__capoo = General(extension, "moesp__capoo", "moe", 3, 3, General.Female)

local emo__liuzu = fk.CreateTriggerSkill{
  name = "emo__liuzu",
  anim_type = "drawcard",
  events = {fk.EventPhaseEnd},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Play and player:getHandcardNum() ~= 6
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setEmotion(player, "./packages/moepack/image/anim/emo__liuzu")
    local x = 6 - player:getHandcardNum()
    if x > 0 then
      player:drawCards(x, self.name)
    else
      room:askForDiscard(target, -x, -x, false, self.name, false)
    end
  end,
}
local emo__liuzu_max = fk.CreateMaxCardsSkill{
  name = "#emo__liuzu_max",
  frequency = Skill.Compulsory,
  fixed_func = function(self, player)
    if player:hasSkill(self) then
      return 6
    end
  end
}
emo__liuzu:addRelatedSkill(emo__liuzu_max)
moesp__capoo:addSkill(emo__liuzu)

local emo__maochong = fk.CreateTriggerSkill{
  name = "emo__maochong",
  anim_type = "defensive",
  events = {fk.TargetConfirmed},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 
    and data.from and player.id ~= data.from and not player.room:getPlayerById(data.from):isNude()
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForDiscard(player, 1, 999, true, self.name, true, ".", "#emo__maochong-discard:"..data.from, true)
    if #cards > 0 then
      self.cost_data = {cards = cards, tos = {data.from}}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setEmotion(player, "./packages/moepack/image/anim/emo__maochong")
    local cards = table.simpleClone(self.cost_data.cards)
    local from = room:getPlayerById(data.from)
    room:throwCard(cards, self.name, player, player)
    if from:isNude() or from.dead then return end
    cards = table.random(from:getCardIds("he"), #cards)
    from:addToPile("$emo__maochong_pile", cards, false, self.name)
  end,
}

local emo__maochong_delay = fk.CreateTriggerSkill{
  name = "#emo__maochong_delay",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return #player:getPile("$emo__maochong_pile") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:obtainCard(player, player:getPile("$emo__maochong_pile"), false, fk.ReasonJustMove)
  end,
}
emo__maochong:addRelatedSkill(emo__maochong_delay)

moesp__capoo:addSkill(emo__maochong)

local emo__touchi = fk.CreateActiveSkill{
  name = "emo__touchi",
  anim_type = "control",
  prompt = "#emo__touchi",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 1,
  target_filter = function(self, to_select, selected)
    return #selected == 0 and to_select ~= Self.id 
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:setEmotion(player, "./packages/moepack/image/anim/emo__touchi")
    local target = room:getPlayerById(effect.tos[1])
    local cards = table.filter(target:getCardIds("h"), function(id) 
      local card = Fk:getCardById(id)
      return card.trueName == "peach" or card.trueName == "analeptic"
    end)
    if #cards > 0 then
      local card = Fk:getCardById(table.random(cards))
      if not player:prohibitUse(card) and not (card.trueName == "peach" and not player:isWounded()) then
        room:useCard{from = player.id, tos = {{player.id}}, card = card}
      else
        room:moveCardTo(card, Card.Void, nil, fk.ReasonJustMove, self.name, "", true)
      end
    else
      if #player:getTableMark("@emo__touchi_from") == 0 then
        local skills = table.map(table.filter(target.player_skills, function (s)
          return s:isPlayerSkill(target) and s.visible
        end), Util.NameMapper)
        if #skills == 0 then return false end
        local choice = room:askForChoice(player, skills, self.name, "#emo__touchi-skill:" .. target.id, true)

        room:addTableMark(target, "@emo__touchi_tar", choice)
        room:addTableMark(player, "emo__touchi_info", {target.id, choice})
        room:handleAddLoseSkills(target, "-"..choice)

        if player:hasSkill(choice, true) then return false end
        room:addTableMark(player, "@emo__touchi_from", choice)
        room:handleAddLoseSkills(player, choice)
      end
    end
  end,

  on_lose = function (self, player, is_death)
    player.room:setPlayerMark(player, "@emo__touchi_from", 0)
    player.room:setPlayerMark(player, "emo__touchi_info", 0)
    -- 吃掉的技能不会还回去
  end,
}

local emo__touchi_delay = fk.CreateTriggerSkill{
  name = "#emo__touchi_delay",
  events = {fk.TargetConfirmed},
  anim_type = "negative",
  priority = 0.99,
  can_trigger = function(self, event, target, player, data)
    if target == player and data.from and data.from ~= player.id then
      local from = player.room:getPlayerById(data.from)
      return table.find(player:getTableMark("emo__touchi_info"), function (mark)
        return mark[1] == data.from
      end) ~= nil
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local from = room:getPlayerById(data.from)
    local skills = {}
    local mark = player:getTableMark("emo__touchi_info")
    for i = #mark, 1, -1 do
      local info = mark[i]
      if info[1] == data.from then
        table.remove(mark, i)
        table.insert(skills, info[2])
      end
    end
    if #skills == 0 then return end
    room:setPlayerMark(player, "emo__touchi_info", mark)

    for _, skill in ipairs(skills) do
      if room:removeTableMark(player, "@emo__touchi_from", skill) then
        room:handleAddLoseSkills(player, "-"..skill)
      end
      room:removeTableMark(from, "@emo__touchi_tar", skill)
      room:handleAddLoseSkills(from, skill)
    end
  end,
}
emo__touchi:addRelatedSkill(emo__touchi_delay)

moesp__capoo:addSkill(emo__touchi)

Fk:loadTranslationTable{
  ["moesp__capoo"] = "咖波", -- 作者：野心家（ZP）
  ["designer:moesp__capoo"] = "ZP",
  
  ["emo__liuzu"] = "六足",
  [":emo__liuzu"] = "锁定技，一名角色的出牌阶段结束时，你将手牌数调整至6；你的手牌上限为6。",

  ["emo__maochong"] = "猫虫",
  [":emo__maochong"] = "每回合限一次，每当你成为其他角色使用牌的目标后，你可以弃置任意数量的牌，然后随机选择其等量的牌扣置其武将牌上，回合结束时令其获得。",
  ["#emo__maochong-discard"] = "猫虫：你可以弃置任意数量的牌，吃掉 %src 等量的牌",
  ["$emo__maochong_pile"] = "猫虫",

  ["emo__touchi"] = "偷吃",
  [":emo__touchi"] = "出牌阶段限一次，你可以吃掉一名其他角色手牌中一张【桃】或【酒】，若你未吃到，且你未吃有技能，改为吃掉其一个技能，直到你成为其使用牌的目标。",
  ["#emo__touchi"] = "偷吃，选择一名其他角色，吃掉其的一张【桃】或【酒】，若未吃到，则吃掉其1个技能！",
  ["#emo__touchi-skill"] = "偷吃：吃掉 %src 一个技能！",
  ["@emo__touchi_tar"] = "被偷吃",
  ["@emo__touchi_from"] = "偷吃",
  ["#emo__touchi_delay"] = "偷吃",

  ["$emo__liuzu1"] = "（走路声）",
  ["$emo__liuzu2"] = "（游泳声）",
  ["$emo__maochong1"] = "（惊叫声）",
  ["$emo__maochong2"] = "（提示声）",
  ["$emo__touchi1"] = "（高兴）",
}

local moesp__songweizl = General(extension, "moesp__songweizl", "moe", 3, 3, General.Female)

local emo__lingjian = fk.CreateTriggerSkill{
  name = "emo__lingjian",
  events = {fk.CardUsing},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local cards = room:getNCards(1)
    player:showCards(cards)
    if Fk:getCardById(cards[1]).type == data.card.type then
      room:obtainCard(player, cards[1], true, fk.ReasonPrey)
    else
      table.insert(room.draw_pile, 1, cards[1])
    end
  end,
}
moesp__songweizl:addSkill(emo__lingjian)


local emo__yuxing = fk.CreateViewAsSkill{
  name = "emo__yuxing",
  pattern = ".",
  interaction = function()
    local names = {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card.type ~= Card.TypeEquip and not card.is_derived and not Self:prohibitUse(card)
      and Self:getMark("emo__yuxing_"..card.type.."-turn") == 0 then
        if (Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card)) then
          table.insertIfNeed(names, card.name)
        end
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and self.interaction.data and Fk:currentRoom():getCardArea(to_select) ~= Player.Equip
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return end
    local card = Fk:cloneCard(self.interaction.data)
    card:addSubcard(cards[1])
    card.skillName = self.name
    return card
  end,
  before_use = function(self, player, use)
    player.room:setPlayerMark(player, "emo__yuxing_"..use.card.type.."-turn", 1)
  end,
  enabled_at_play = function(self, player)
    return not player:isKongcheng()
  end,
  enabled_at_response = function(self, player, response)
    if not player:isKongcheng() then
      for _, id in ipairs(Fk:getAllCardIds()) do
        local card = Fk:getCardById(id)
        if card.type ~= Card.TypeEquip and not card.is_derived and not Self:prohibitUse(card)
        and Self:getMark("emo__yuxing_"..card.type.."-turn") == 0 then
          if Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card) then
            return true
          end
        end
      end
    end
  end,
}
moesp__songweizl:addSkill(emo__yuxing)

local emo__zhiwang = fk.CreateTriggerSkill{
  name = "emo__zhiwang",
  events = {fk.AfterCardsMove},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:isKongcheng() and #player:getTableMark("@$emo__zhiwang") > 0 then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Player.Hand then
              return true
            end
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player.room:setPlayerMark(player, "@$emo__zhiwang", 0)
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self) and target == player
  end,
  on_refresh = function (self, event, target, player, data)
    local mark = player:getTableMark("@$emo__zhiwang")
    table.insertIfNeed(mark, data.card.trueName)
    player.room:setPlayerMark(player, "@$emo__zhiwang", mark)
  end,
}

local emo__zhiwang_prohibit = fk.CreateProhibitSkill{
  name = "#emo__zhiwang_prohibit",
  prohibit_use = function(self, player, card)
    return player:hasSkill("emo__zhiwang") and card and table.contains(player:getTableMark("@$emo__zhiwang"), card.trueName)
  end,
}
emo__zhiwang:addRelatedSkill(emo__zhiwang_prohibit)

moesp__songweizl:addSkill(emo__zhiwang)

Fk:loadTranslationTable{
  ["moesp__songweizl"] = "怂为真理", -- 作者：怂为真理
  ["designer:moesp__songweizl"] = "怂为真理",
  
  ["emo__lingjian"] = "灵见",
  [":emo__lingjian"] = "锁定技，每当你使用牌后，你展示牌堆顶牌，若此牌的类别与与你使用的牌：相同，你获得之；不同，将之放回牌堆顶。",

  ["emo__yuxing"] = "愉行",
  [":emo__yuxing"] = "每回合每种类别限一次，可以将一张手牌当任意基本牌或锦囊牌使用或打出。",

  ["emo__zhiwang"] = "执妄",
  [":emo__zhiwang"] = "锁定技，当你使用一张牌时，记录之，你不能使用与记录牌名相同的牌。每当你失去手牌后，若你没有手牌，你清除牌名记录。",
  ["@$emo__zhiwang"] = "执妄",
}

local moesp__makima = General(extension, "moesp__makima", "moe", 4, 4, General.Female)

local emo__zhipei = fk.CreateTriggerSkill{
  name = "emo__zhipei",
  events = {fk.EventPhaseStart, fk.Damaged},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and (event == fk.Damaged or player.phase == Player.Start)
    and player:getMark("@@emo__zhipei_failed-turn") == 0
  end,
  on_cost = function(self, event, target, player, data)
    local tos = player.room:askForChoosePlayers(player, table.map(player.room.alive_players, Util.IdMapper), 1, 1, "#emo__zhipei-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    to:drawCards(1, self.name)
    if not to.dead and not to.chained then
      to:setChainState(true)
    end
  end,
}

local emo__zhipei_control = fk.CreateTriggerSkill{
  name = "#emo__zhipei_control",
  events = {fk.AfterCardTargetDeclared},
  anim_type = "control",
  can_trigger = function(self, event, target, player, data)
    return target ~= player and target.chained and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and player:getMark("@@emo__zhipei_failed-turn") == 0 and data.tos and data.card.skill:getMinTargetNum() < 2
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local targets = {}
    for _, p in ipairs(room.alive_players) do
      if not target:isProhibited(p, data.card) and data.card.skill:modTargetFilter(p.id, {}, target, data.card, true) then
        table.insert(targets, p.id)
      end
    end
    if #targets == 0 then return false end
    local choose_num = math.min(#targets, #TargetGroup:getRealTargets(data.tos))
    local tos = player.room:askForChoosePlayers(player, targets, 1, choose_num, "#emo__zhipei_control-choose::"..target.id..":"..data.card:toLogString()..":"..choose_num, self.name, true, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = self.cost_data
    room:doIndicate(player.id, {target.id})
    room:sendLog{ type = "#Changetargets", from = target.id, to = tos, arg = self.name, arg2 = data.card:toLogString()}
    room:sortPlayersByAction(tos)
    data.tos = table.map(tos, function(p) return {p} end)
  end,
}
emo__zhipei:addRelatedSkill(emo__zhipei_control)

moesp__makima:addSkill(emo__zhipei)

local emo__qiyue = fk.CreateTriggerSkill{
  name = "emo__qiyue",
  anim_type = "defensive",
  events = {fk.Death , fk.EnterDying},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.EnterDying then
      return player:hasSkill(self) and target == player and table.find(player.room.alive_players, function(p) return p.chained end)
    else
      return player:hasSkill(self,true) and target == player
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EnterDying then
      room:addPlayerMark(player, "@@emo__zhipei_failed-turn")
      local x = 0
      for _, p in ipairs(room.alive_players) do
        if p.chained then
          p:setChainState(false)
          x = x + 1
        end
      end
      if x > 0 and not player.dead then
        player:drawCards(x, self.name)
      end
      if not player.dead and player:isWounded() then
        room:recover { num = 1-player.hp, skillName = self.name, who = player , recoverBy = player}
      end
    else
      local id = table.find(room.void, function (id) return Fk:getCardById(id).name == "makima__peach" end)
      if id then
        table.removeOne(room.void, id)
        table.insert(room.draw_pile, math.random(1, #room.draw_pile), id)
        room:setCardArea(id, Card.DrawPile, nil)
        room:doBroadcastNotify("UpdateDrawPile", tostring(#room.draw_pile))
      end
    end
  end,
}
moesp__makima:addSkill(emo__qiyue)

Fk:loadTranslationTable{
  ["moesp__makima"] = "玛奇玛",
  ["designer:moesp__makima"] = "理塘王",
  
  ["emo__zhipei"] = "支配",
  [":emo__zhipei"] = "①准备阶段开始时，或你受到伤害后，你可以令一名角色摸一张牌并横置。②每回合限一次，每当一名已横置的其他角色使用牌指定目标时，你可以为此牌重新指定目标（至少一个目标）。",
  ["#emo__zhipei-choose"] = "支配：你可以令一名角色摸一张牌并横置",
  ["#emo__zhipei_control"] = "支配",
  ["#emo__zhipei_control-choose"] = "支配：你可以为 %dest 使用的%arg重新指定目标（至少1个，至多%arg2个）",
  ["#Changetargets"] = "由于 %arg 的效果，%from 使用的 %arg2 目标改为 %to",

  ["emo__qiyue"] = "契约",
  [":emo__qiyue"] = "①锁定技，每当你进入濒死状态时，若有横置的角色，你重置这些角色并摸等量张牌，且令〖支配〗于本回合失效，然后你将体力值恢复至1点。②锁定技，当你死亡时，将一张“生姜炒肉”洗入牌堆。",
  ["@@emo__zhipei_failed-turn"] = "支配失效",
}

local moesp__caohua = General(extension, "moesp__caohua", "moe", 3, 3, General.Female)
moesp__caohua.subkingdom = "wei"

local emo__biyi = fk.CreateTriggerSkill{
  name = "emo__biyi",
  events = {fk.RoundStart, fk.Deathed},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    else
      return player:hasSkill(self, true) and target.id == player:getMark(self.name)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__biyi-choose", self.name, false)
      local to = room:getPlayerById(tos[1])
      room:addPlayerMark(to, "@@emo__biyi_other", 1)
      room:setPlayerMark(player, self.name, to.id)
      local general = to.general
      if to.deputyGeneral ~= "" and Fk.generals[to.deputyGeneral]
      and room:askForChoice(player, {"mainGeneral", "deputyGeneral"}, self.name) == "deputyGeneral" then
        general = to.deputyGeneral
      end
      room:setPlayerMark(player, "@emo__biyi", general)
      local skills = {}
      for _, skill_name in ipairs(Fk.generals[general]:getSkillNameList()) do
        local s = Fk.skills[skill_name]
        if not (s.lordSkill and player.role ~= "lord") and not player:hasSkill(s,true)
        and not (#s.attachedKingdom > 0 and not table.contains(s.attachedKingdom, player.kingdom)) then
          table.insert(skills, s.name)
        end
      end
      if #skills > 0 then
        room:setPlayerMark(player, "emo__biyi_skill", skills)
        room:handleAddLoseSkills(player, table.concat(skills, "|"), nil)
      end
    else
      room:setPlayerMark(player, "@emo__biyi", 0)
      local skills = player:getMark("emo__biyi_skill")
      if type(player:getMark("emo__biyi_skill")) == "table" and #skills > 0 then
        room:handleAddLoseSkills(player, "-"..table.concat(skills, "|-"), nil)
      end
      room:handleAddLoseSkills(player, "emo__guili", nil)
    end
  end,

  on_lose = function (self, player)
    local room = player.room
    local to = room:getPlayerById(player:getMark(self.name))
    if to then
      room:removePlayerMark(to, "@@emo__biyi_other")
    end
    room:setPlayerMark(player, "@emo__biyi", 0)
    room:setPlayerMark(player, self.name, 0)
    room:setPlayerMark(player, "emo__biyi_skill", 0)
  end,
}
moesp__caohua:addSkill(emo__biyi)

local emo__shuangfei = fk.CreateTriggerSkill{
  name = "emo__shuangfei",
  anim_type = "offensive",
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    local room = player.room
    if player:hasSkill(self) and not data.card:isVirtual() and data.damageDealt and data.tos and #data.tos > 0 then
      local user
      if target == player then
        local other = room:getPlayerById(player:getMark("emo__biyi"))
        if other and other:isAlive() then
          user = other
        end
      elseif target:getMark("@@emo__biyi_other") > 0 then
        user = player
      end
      if user and not user:isNude() then
        local tos = TargetGroup:getRealTargets(data.tos)
        return table.find(tos, function (pid)
          return not user:isProhibited(room:getPlayerById(pid), Fk:cloneCard(data.card.name))
        end)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local user = (target == player) and room:getPlayerById(player:getMark("emo__biyi")) or player
    local color = data.card:getColorString()
    local colorTosuit = {["red"] = "heart,diamond",["black"]="spade,club",["nocolor"]="nosuit"}
    local throw = room:askForDiscard(user, 1, 1, true, self.name, true, ".|.|"..colorTosuit[color], "#emo__shuangfei:::"..color..":"..data.card.name)
    if #throw > 0 then
      self.cost_data = throw
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local user = (target == player) and room:getPlayerById(player:getMark("emo__biyi")) or player
    room:throwCard(self.cost_data, self.name, user, user)
    room:useVirtualCard(data.card.name, nil, user, table.map(TargetGroup:getRealTargets(data.tos), Util.Id2PlayerMapper),self.name,true)
  end,
}
moesp__caohua:addSkill(emo__shuangfei)

local emo__xiangshou = fk.CreateTriggerSkill{
  name = "emo__xiangshou",
  anim_type = "support",
  frequency = Skill.Compulsory,
  events = {fk.AskForCardUse, fk.AskForCardResponse},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and data.pattern and (event == fk.AskForCardResponse or data.cardName == "jink") then
      local user
      if target == player then
        local other = player.room:getPlayerById(player:getMark("emo__biyi"))
        if other and other:isAlive() then
          user = other
        end
      elseif target:getMark("@@emo__biyi_other") > 0 then
        user = player
      end
      return user and not user:isNude()
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local user = (target == player) and room:getPlayerById(player:getMark("emo__biyi")) or player
    local prompt = (event == fk.AskForCardUse) and "#emo__xiangshou-jink:" or "#emo__xiangshou-resp:"
    local card = room:askForCard(user, 1, 1, true, self.name, true, data.pattern, prompt..target.id)
    if #card > 0 then
      self.cost_data = card[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local card = Fk:getCardById(self.cost_data)
    local user = (target == player) and room:getPlayerById(player:getMark("emo__biyi")) or player
    if event == fk.AskForCardUse then
      data.result = {
        from = target.id,
        card = card,
      }
      if data.eventData then
        data.result.toCard = data.eventData.toCard
        data.result.responseToEvent = data.eventData.responseToEvent
      end
    else
      data.result = card
    end
    if not user.dead then user:drawCards(1, self.name) end
    if not target.dead then target:drawCards(1, self.name) end
    return true
  end
}
moesp__caohua:addSkill(emo__xiangshou)

local emo__guili = fk.CreateTriggerSkill{
  name = "emo__guili",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      return table.find(player.room.alive_players, function (p)
        return p:getMark("@emo__guili-turn") > 0
      end)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    for _, p in ipairs(room:getAlivePlayers()) do
      local n = p:getMark("@emo__guili-turn")
      if n > 0 then
        room:askForDiscard(p, n, n, true, self.name, false)
        if not player.dead and target == player then
          player:drawCards(1, self.name)
        end
      end
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    return player:hasSkill(self, true) 
  end,
  on_refresh = function (self, event, target, player, data)
    for _, move in ipairs(data) do
      if move.to and move.to ~= player.id and move.toArea == Card.PlayerHand then
        local to = player.room:getPlayerById(move.to)
        if not to.dead and to.phase == Player.NotActive then
          player.room:addPlayerMark(to, "@emo__guili-turn", #move.moveInfo)
        end
      end
    end
  end,
}
moesp__caohua:addRelatedSkill(emo__guili)


Fk:loadTranslationTable{
  ["moesp__caohua"] = "萌曹华",
  ["designer:moesp__caohua"] = "才疏学浅的升卿",
  
  ["emo__biyi"] = "比翼",
  [":emo__biyi"] = "锁定技，每轮开始时，若你没有发动过此技能，你令一名其他角色获得“翼”标记，然后获得其一张武将牌上的所有技能。当该角色死亡后，你失去以此法获得的技能并获得〖归离〗。",
  ["@@emo__biyi_other"] = "翼",
  ["@emo__biyi"] = "比翼",
  ["#emo__biyi-choose"] = "比翼：令一名其他角色获得“翼”标记，获得其武将牌上的技能",

  ["emo__shuangfei"] = "双飞",
  [":emo__shuangfei"] = "你或拥有“翼”的角色使用的实体牌结算结束后，若此牌造成了伤害，另一方可以弃置一张与此牌同颜色的牌，视为对相同目标角色使用此牌。",
  ["#emo__shuangfei"] = "双飞：你可以弃置一张%arg牌，视为对相同目标角色使用%arg2",
  
  ["emo__xiangshou"] = "相守",
  [":emo__xiangshou"] = "每当你或拥有“翼”的角色需要使用【闪】或打出一张牌时，另一方可以替其使用或打出之，然后两者各摸一张牌。",
  ["#emo__xiangshou-jink"] = "相守：你可以替 %src 使用【闪】，然后你与其各摸一张牌",
  ["#emo__xiangshou-resp"] = "相守：你可以替 %src 打出其需要的牌，然后你与其各摸一张牌",
  
  ["emo__guili"] = "归离",
  [":emo__guili"] = "锁定技，其他角色于其回合外获得牌后，须于当前回合结束时弃置等量牌，若是你的回合，你摸一张牌。",
  ["@emo__guili-turn"] = "归离",

  ["$emo__biyi1"] = "凰凤化越，彩翼犹存。",
  ["$emo__biyi2"] = "与君有灵犀，一双彩翼，载得许多梦。",
  ["$emo__shuangfei1"] = "小女不才，愿与君双宿而双飞。",
  ["$emo__shuangfei2"] = "身有彩鳞双飞翼，落羽紫微帝王家。",
  ["$emo__xiangshou1"] = "愿以彩翼，为君遮风雨、避灾祸。",
  ["$emo__xiangshou2"] = "身披彩翼，心有灵犀。",
  ["$emo__guili1"] = "当归、当归，日暮南山鸟倦飞。",
  ["$emo__guili2"] = "凤非梧桐不栖，小女遍寻城中未见一木。",
  ["~moesp__caohua"] = "自古忠孝难两全。",
}


local moesp__qiongmei = General(extension, "moesp__qiongmei", "moe", 2, 3, General.Female)


local emo__weiyi = fk.CreateTriggerSkill{
  name = "emo__weiyi",
  events = {fk.GameStart, fk.Damage},
  anim_type = "support",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) then
      if event == fk.GameStart then
        return player:getMark("emo__weiyi_bro") == 0
      else
        return target and target.id == player:getMark("emo__weiyi_bro")
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.GameStart then
      local others = room:getOtherPlayers(player, false)
      if #others == 0 then return end -- 十常侍！
      local tos = room:askForChoosePlayers(player, table.map(others, Util.IdMapper), 1, 1, "#emo__weiyi-bro", self.name, false)
      local to = room:getPlayerById(tos[1])
      room:setPlayerMark(player, "emo__weiyi_bro", to.id)
      room:addPlayerMark(to, "@@WYbro")
    else
      local n = 0
      player.room.logic:getActualDamageEvents(1, function(e)
        if e.data[1].from == target then
          n = n + e.data[1].damage
        end
      end)
      if n > 0 then
        player:drawCards(n, self.name)
      end
    end
  end,

  refresh_events = {fk.EventLoseSkill, fk.BuryVictim},
  can_refresh = function(self, event, target, player, data)
    if target ~= player then return false end
    if event == fk.EventLoseSkill then
      return data == self and not player:hasSkill("emo__gutong", true)
    else
      return target:hasSkill(self, true, true)
    end
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    local bro = room:getPlayerById(player:getMark("emo__weiyi_bro"))
    if bro then
      room:removePlayerMark(bro, "@@WYbro")
    end
  end,
}
local emo__weiyi_maxcard = fk.CreateMaxCardsSkill{
  name = "#emo__weiyi_maxcard",
  frequency = Skill.Compulsory,
  fixed_func = function(self, player)
    if player:hasSkill(emo__weiyi) then
      local bro = Fk:currentRoom():getPlayerById(player:getMark("emo__weiyi_bro"))
      if bro and not bro.dead then
        return bro.hp
      end
    end
  end
}
moesp__qiongmei:addSkill(emo__weiyi)

local emo__gutong = fk.CreateTriggerSkill{
  name = "emo__gutong",
  events = {fk.EnterDying, fk.Damaged},
  anim_type = "support",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damaged then
      return player:hasSkill(self) and target.id == player:getMark("emo__weiyi_bro")
    elseif player:hasSkill(self) and target == player then
      local bro = player.room:getPlayerById(player:getMark("emo__weiyi_bro"))
      return bro and not bro.dead
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local bro = room:getPlayerById(player:getMark("emo__weiyi_bro"))
    if event == fk.Damaged then
      room:loseHp(player, 1, self.name)
      room:changeMaxHp(player, 1)
    else
      room:loseHp(bro, 1, self.name)
      if bro.dead then return end
      if player:isWounded() and not player.dead then
        room:recover { num = 1, skillName = self.name, who = player , recoverBy = player} 
      end
      room:changeMaxHp(bro, 1)
    end
  end,
}
moesp__qiongmei:addSkill(emo__gutong)

local emo__huran = fk.CreateTriggerSkill{
  name = "emo__huran",
  events = {fk.TurnEnd},
  anim_type = "support",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    local bro = player.room:getPlayerById(player:getMark("emo__weiyi_bro"))
    if player:hasSkill(self) and bro and not bro.dead then
      self.cost_data = {tos = {bro.id}}
      return target == bro or target == player
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local bro = room:getPlayerById(player:getMark("emo__weiyi_bro"))
    local choices = {}
    if player:isWounded() or bro:getHandcardNum() < bro.maxHp then table.insert(choices, "emo__huran_choice1") end
    if bro:isWounded() or player:getHandcardNum() < player.maxHp then table.insert(choices, "emo__huran_choice2") end
    if #choices == 0 then return end
    local choice = room:askForChoice(player, choices, self.name, "#emo__huran-choice:"..bro.id)
    local recoverOne = choice:endsWith("1") and player or bro
    local drawOne = choice:endsWith("2") and player or bro
    if recoverOne:isWounded() and not recoverOne.dead then
      room:recover { num = 1, skillName = self.name, who = recoverOne , recoverBy = player} 
    end
    if drawOne:getHandcardNum() < drawOne.maxHp and not drawOne.dead then
      drawOne:drawCards(drawOne.maxHp-drawOne:getHandcardNum(), self.name)
    end
  end,
}
moesp__qiongmei:addSkill(emo__huran)


Fk:loadTranslationTable{
  ["moesp__qiongmei"] = "穹妹", -- by 口水黄豆
  ["designer:moesp__qiongmei"] = "口水黄豆",
  
  ["emo__weiyi"] = "唯依",
  [":emo__weiyi"] = "锁定技，①游戏开始时，你令一名其他角色获得“兄”标记。②你的手牌上限等于该角色体力值。③每当该角色造成伤害后，你摸X张牌（X为其本回合造成的伤害）。",
  ["@@WYbro"] = "兄",
  ["#emo__weiyi-bro"] = "唯依：你令一名其他角色获得“兄”标记",

  ["emo__gutong"] = "孤痛",
  [":emo__gutong"] = "锁定技，①有“兄”标记的角色受到伤害后，你失去一点体力并增加一点体力上限。②每当你进入濒死状态时，若有“兄”标记的角色存活，你令其失去一点体力，然后若其存活，你回复一点体力并令其增加一点体力上限。",

  ["emo__huran"] = "互染",
  [":emo__huran"] = "锁定技，你或有“兄”标记的角色的回合结束时，你选择令你与其分别执行：回复一点体力/将手牌摸至体力上限。",
  ["#emo__huran-choice"] = "互染：选择你和 %src 执行的内容",
  ["emo__huran_choice1"] = "我回复1点体力，兄摸牌至体力上限",
  ["emo__huran_choice2"] = "兄回复1点体力，我摸牌至体力上限",
}

local moesp__yuyaomeng = General(extension, "moesp__yuyaomeng", "moe", 4, 4, General.Female)

local emo__yuge = fk.CreateTriggerSkill{
  name = "emo__yuge",
  anim_type = "control",
  events = {fk.TurnStart},
  can_trigger = function(self, event, target, player, data)
    return target ~= player and player:hasSkill(self) and not player:isKongcheng() and not player:isRemoved() and not target:isRemoved()
  end,
  on_cost = function (self, event, target, player, data)
    local x = player:distanceTo(target)
    local cards = player.room:askForDiscard(player, x, x, false, self.name, true, ".|.|.|hand", "#emo__yuge::"..target.id..":"..x, true)
    if #cards == x then
      self.cost_data = cards
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:setPlayerMark(player, "@@emo__yuge-turn", target.id)
    room:throwCard(self.cost_data, self.name, player, player)
  end,
}

local emo__yuge_delay = fk.CreateTriggerSkill{
  name = "#emo__yuge_delay",
  mute = true,
  events = {fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    return not player.dead and player:getMark("@@emo__yuge-turn") == target.id
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local ids = {}
    player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
      for _, move in ipairs(e.data) do
        if move.from == target.id then
          for _, info in ipairs(move.moveInfo) do
            if player.room:getCardArea(info.cardId) == Card.DiscardPile and Fk:getCardById(info.cardId).type ~= Card.TypeEquip then
              if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                table.insertIfNeed(ids, info.cardId)
              end
            end
          end
        end
      end
      return false
    end, Player.HistoryTurn)
    if #ids > 0 then
      room:obtainCard(player, ids, true, fk.ReasonPrey)
    end
  end,
}
emo__yuge:addRelatedSkill(emo__yuge_delay)

local emo__yuge_prohibit = fk.CreateProhibitSkill{
  name = "#emo__yuge_prohibit",
  is_prohibited = function(self, from, to, card)
    return card and card.type == Card.TypeTrick and to:getMark("@@emo__yuge-turn") ~= 0
  end,
}
emo__yuge:addRelatedSkill(emo__yuge_prohibit)

moesp__yuyaomeng:addSkill(emo__yuge)

local emo__qiren = fk.CreateViewAsSkill{
  name = "emo__qiren",
  anim_type = "offensive",
  pattern = "slash",
  prompt = "#emo__qiren",
  card_filter = function(self, to_select, selected)
    if #selected > 1 then return false end
    return #selected == 0 or Fk:getCardById(to_select).color ~= Fk:getCardById(selected[1]).color
  end,
  view_as = function(self, cards)
    if #cards ~= 2 then return nil end
    local c = Fk:cloneCard("slash")
    c.skillName = self.name
    c:addSubcards(cards)
    return c
  end,
  before_use = function(self, player, use)
    use.extraUse = true
  end,
  enabled_at_response = function(self, player, response)
    return not response and #player:getCardIds("he") > 1
  end,
}
local emo__qiren_tm = fk.CreateTargetModSkill{
  name = "#emo__qiren_tm",
  bypass_times = function(self, player, skill, scope, card, to)
    return card and to and table.contains(card.skillNames, "emo__qiren") and scope == Player.HistoryPhase 
    and to:getHandcardNum() ~= to.maxHp
  end,
  bypass_distances = function(self, player, skill, card, to)
    return card and to and table.contains(card.skillNames, "emo__qiren") and to:getHandcardNum() ~= to.maxHp
  end,
}
emo__qiren:addRelatedSkill(emo__qiren_tm)

local emo__qiren_prohibit = fk.CreateProhibitSkill{
  name = "#emo__qiren_prohibit",
  is_prohibited = function(self, from, to, card)
    return card and table.contains(card.skillNames, "emo__qiren") and to.maxHp == to:getHandcardNum()
  end,
}
emo__qiren:addRelatedSkill(emo__qiren_prohibit)

moesp__yuyaomeng:addSkill(emo__qiren)


Fk:loadTranslationTable{
  ["moesp__yuyaomeng"] = "渔妖梦",
  ["#moesp__yuyaomeng"] = "渔舟的半灵",
  ["designer:moesp__yuyaomeng"] = "妖梦厨",
  ["illustrator:moesp__yuyaomeng"] = "AI",
  
  ["emo__yuge"] = "渔歌",
  [":emo__yuge"] = "其他角色的回合开始时，你可以弃置X张手牌（X为你至其的距离），若如此做，此回合内你不为锦囊牌的合法目标，当前回合结束时，你获得弃牌堆中其本回合失去的所有非装备牌。",
  ["#emo__yuge"] = "渔歌：你可弃%arg张手牌，%dest回合结束时，你获得弃牌堆中其本回合失去的所有非装备牌",
  ["@@emo__yuge-turn"] = "渔歌",
  ["#emo__yuge_prohibit"] = "渔歌",
  ["#emo__yuge_delay"] = "渔歌",

  ["emo__qiren"] = "鳍刃",
  [":emo__qiren"] = "你可以将两张不同颜色的牌当无距离和次数限制的【杀】对手牌数不等于体力上限的其他角色使用。",
  ["#emo__qiren"] = "将两张不同颜色的牌当【杀】对手牌数不等于体力上限的角色使用",
}

local moesp__lihuazou = General(extension, "moesp__lihuazou", "moe", 4, 4, General.Female)

local emo__chaopin = fk.CreateTriggerSkill{
  name = "emo__chaopin",
  anim_type = "switch",
  switch_skill_name = "emo__chaopin",
  frequency = Skill.Compulsory,
  events = {fk.CardUsing, fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if player == target and player:hasSkill(self) then
      if event == fk.CardUsing then
        if data.card.trueName == "slash" and player:getSwitchSkillState(self.name) == fk.SwitchYang then
          local events = player.room.logic:getEventsOfScope(GameEvent.UseCard, 3, function (e)
            local use = e.data[1]
            return use and use.from == player.id and use.card.trueName == "slash"
          end, Player.HistoryTurn) 
          return #events == 3 and events[3].data[1] == data
        end
      else
        return player:getSwitchSkillState(self.name) == fk.SwitchYin and player.phase == Player.Finish
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:broadcastProperty(player, "MaxCards")
    if event == fk.CardUsing then
      data.disresponsiveList = table.map(room.alive_players, Util.IdMapper)
      data.additionalDamage = (data.additionalDamage or 0) + 1
    else
      room:loseHp(player, 1, self.name)
      if not player.dead then
        player:drawCards(player.maxHp, self.name)
      end
    end 
  end,
}
local emo__chaopin_tm = fk.CreateTargetModSkill{
  name = "#emo__chaopin_tm",
  residue_func = function(self, player, skill, scope, card)
    if skill and scope and skill.trueName == "slash_skill" and scope == Player.HistoryPhase 
    and player:hasSkill(emo__chaopin) and player:getSwitchSkillState("emo__chaopin") == fk.SwitchYang then
      return 2
    end
  end,
}
emo__chaopin:addRelatedSkill(emo__chaopin_tm)
local emo__chaopin_maxcards = fk.CreateMaxCardsSkill{
  name = "#emo__chaopin_maxcards",
  correct_func = function(self, player)
    if player:hasSkill(emo__chaopin) and player:getSwitchSkillState("emo__chaopin") == fk.SwitchYang then
      return 2
    end
  end,
}
emo__chaopin:addRelatedSkill(emo__chaopin_maxcards)
moesp__lihuazou:addSkill(emo__chaopin)

local emo__yinren = fk.CreateActiveSkill{
  name = "emo__yinren",
  anim_type = "support",
  prompt = "#emo__yinren-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_num = 0,
  card_filter = Util.FalseFunc,
  target_num = 0,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local cards = room:getCardsFromPileByRule("slash")
    if #cards == 0 then return end
    local id = cards[1]
    room:obtainCard(player, id, true, fk.ReasonDraw)
    if room:getCardArea(id) == Card.PlayerHand and room:getCardOwner(id) == player then
      room:setCardMark(Fk:getCardById(id), "@@emo__yinren", 1)
    end
  end,
}

local emo__yinren_filter = fk.CreateFilterSkill{
  name = "#emo__yinren_filter",
  anim_type = "offensive",
  card_filter = function(self, to_select, player)
    return player:hasSkill(self) and to_select.trueName == "slash" and
    table.contains(player.player_cards[Player.Hand], to_select.id)
  end,
  view_as = function(self, to_select)
    local card = Fk:cloneCard(to_select.name, Card.NoSuit, to_select.number)
    card.skillName = "emo__yinren"
    return card
  end,
}

local emo__yinren_delay = fk.CreateTriggerSkill{
  name = "#emo__yinren_delay",
  mute = true,
  events = {fk.Damage},
  can_trigger = function(self, event, target, player, data)
    return player == target and not player.dead and data.card and data.card:getMark("@@emo__yinren") > 0
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:changeShield(player, 1)
    if data.to:isAlive() and player:getMark("emo__yinren_levelup") > 0 then
      data.to:turnOver()
    end
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    return true
  end,
  on_refresh = function(self, event, target, player, data)
    local room = player.room
    for _, move in ipairs(data) do
      if move.toArea ~= Card.Processing then
        for _, info in ipairs(move.moveInfo) do
          local card = Fk:getCardById(info.cardId)
          if card:getMark("@@emo__yinren") > 0 then
            room:setCardMark(card, "@@emo__yinren", 0)
          end
        end
      end
    end
  end,
}
emo__yinren:addRelatedSkill(emo__yinren_filter)
emo__yinren:addRelatedSkill(emo__yinren_delay)
moesp__lihuazou:addSkill(emo__yinren)

local emo__taixin = fk.CreateTriggerSkill{
  name = "emo__taixin",
  anim_type = "defensive",
  frequency = Skill.Limited,
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and data.damage >= (player.hp + player.shield)
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__taixin-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:recastCard(player:getCardIds("he"), player, self.name)
    local targets = table.map(room:getOtherPlayers(player), Util.IdMapper)
    if not player.dead and #targets > 0 then
      local tos = player.room:askForChoosePlayers(player, targets, 1, 1, "#emo__taixin-choose:::"..data.damage, self.name, false)
      if #tos > 0 then
        room:damage{
          from = player,
          to = room:getPlayerById(tos[1]),
          damage = data.damage,
          damageType = data.damageType,
          skillName = self.name,
        }
      end
    end
    room:setPlayerMark(player, "emo__yinren_levelup", 1)
    return true
  end,
}
moesp__lihuazou:addSkill(emo__taixin)


Fk:loadTranslationTable{
  ["moesp__lihuazou"] = "立华奏",
  ["designer:moesp__lihuazou"] = "是沐沐吖",
  
  ["emo__chaopin"] = "超频",
  [":emo__chaopin"] = "转换技，锁定技，阳：当你使用本回合第三张【杀】时，此【杀】不可响应且伤害+1（阳状态下，你的手牌上限和使用【杀】次数上限+2）；阴：结束阶段，你失去一点体力并摸等于体力上限张牌。",

  ["emo__yinren"] = "音刃",
  [":emo__yinren"] = "出牌阶段限一次，你可以摸一张【杀】，此【杀】造成伤害后，你获得一点护甲。你的【杀】视为无花色。",
  ["#emo__yinren-prompt"] = "音刃：你可以摸一张【杀】，此【杀】造成伤害后，你获得一点护甲",
  ["@@emo__yinren"] = "音刃",
  ["#emo__yinren_filter"] = "音刃",
  ["#emo__yinren_delay"] = "音刃",

  ["emo__taixin"] = "天心",
  [":emo__taixin"] = "限定技，当你受到致命伤害时，你可以重铸所有牌，防止此伤害并对一名其他角色造成同属性的等量伤害，然后修改〖音刃〗：此【杀】造成伤害后，令受伤害的角色翻面。",
  ["#emo__taixin-invoke"] = "天心：你可以重铸所有牌，防止此伤害并造成等量伤害，然后修改〖音刃〗",
  ["#emo__taixin-choose"] = "天心:对一名其他角色造成 %arg 点伤害!",
  ["$emo__taixin1"] = "",
  ["$emo__taixin2"] = "",
}


local moesp__zige = General(extension, "moesp__zige", "moe", 3, 3, General.Female)
moesp__zige.subkingdom = "huan"
Fk:loadTranslationTable{
  ["huan"] = "幻",
}

local emo__qianfei = fk.CreateTriggerSkill{
  name = "emo__qianfei",
  anim_type = "support",
  events = {fk.DrawNCards, fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if event == fk.DrawNCards then
      return player:hasSkill(self) and target == player
    else
      return player:hasSkill(self) and target.phase ~= Player.NotActive and target:getMark("emo__qianfei-turn") == 0 and data.card.color == Card.Black and data.tos and #data.tos > 0
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    if event == fk.DrawNCards then
      local n = #table.filter(player.room.alive_players, function(p) return p:getHandcardNum() < player:getHandcardNum() end)
      if n > 0 and room:askForSkillInvoke(player, self.name, nil, "#emo__qianfei-draw:::"..n) then
        self.cost_data = n
        return true
      end
    else
      room:addPlayerMark(target, "emo__qianfei-turn")
      local targets = {}
      for _, pid in ipairs(TargetGroup:getRealTargets(data.tos)) do
        local p = room:getPlayerById(pid)
        if not p.dead then
          table.insertIfNeed(targets, pid)
        end
      end
      if #targets == 0 then return false end
      local card = room:askForDiscard(player, 1, 1, true, self.name, true, "." , "#emo__qianfei-invoke::"..data.from..":"..data.card:toLogString(), true)
      if #card > 0 then
        self.cost_data = {card, targets}
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.DrawNCards then
      data.n = data.n + self.cost_data
    else
      room:throwCard(self.cost_data[1], self.name, player, player)
      local tos = room:askForChoosePlayers(player, self.cost_data[2], 1, 1, "#emo__qianfei-recover:::"..data.card:toLogString(), self.name, true)
      if #tos > 0 then
        local to = room:getPlayerById(tos[1])
        if to:isWounded() then
          room:recover({ who = to,  num = 1, recoverBy = player, skillName = self.name }) 
        end
      else
        room:doCardUseEffect(data) -- FIXEME 五谷
      end
    end
  end,
}
moesp__zige:addSkill(emo__qianfei)


local emo__heli = fk.CreateTriggerSkill{
  name = "emo__heli",
  anim_type = "control",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player.phase ~= Player.NotActive and player:usedSkillTimes(self.name, Player.HistoryTurn) < 1 and (data.card.type == Card.TypeBasic or data.card:isCommonTrick())
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local all_choices = {"emo__heli_draw", "emo__heli_limit", "emo__heli_recover", "emo__heli_give"}
    local choices = room:askForChoices(player, all_choices, 1, 2, self.name, nil, false)
    if table.contains(choices, "emo__heli_limit") then
      room:setPlayerMark(player, "@@emo__heli_limit-turn", 1)
    end
    if table.contains(choices, "emo__heli_draw") then
      room:askForGuanxing(player, room:getNCards(2))
      player:drawCards(2, self.name)
    end
    if table.contains(choices, "emo__heli_recover") then
      if player:isWounded() and not player.dead then
        room:recover({ who = player,  num = 1, recoverBy = player, skillName = self.name }) 
      end
      room:addPlayerMark(player, "AddMaxCards-turn", 999)
    end
    if table.contains(choices, "emo__heli_give") and not player.dead then
      local targets = table.filter(room:getOtherPlayers(player), function(p) return not p:isKongcheng() end)
      room:setPlayerMark(player, "@@emo__heli_damage", 1)
      if #targets > 0 then
        local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__heli-choose", self.name, true)
        if #tos > 0 then
          local to = room:getPlayerById(tos[1])
          local card = room:askForCard(to, 1, 1, false, self.name, false, ".", "#emo__heli-give:"..player.id)
          if #card > 0 then
            room:obtainCard(player, card[1], false, fk.ReasonGive)
          end
        end
      end
    end
    data.nullifiedTargets = table.map(room.alive_players, Util.IdMapper)
  end,

  refresh_events = {fk.AfterCardUseDeclared},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@@emo__heli_damage") > 0 and data.card.is_damage_card
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@@emo__heli_damage", 0)
    data.disresponsiveList = table.map(player.room.alive_players, Util.IdMapper)
  end,
}

local emo__heli_targetmod = fk.CreateTargetModSkill{
  name = "#emo__heli_targetmod",
  bypass_times = function(self, player, skill, scope, card)
    return player:getMark("@@emo__heli_limit-turn") > 0 and card
  end,
  bypass_distances = function(self, player, skill, card)
    return player:getMark("@@emo__heli_limit-turn") > 0 and card
  end,
}
emo__heli:addRelatedSkill(emo__heli_targetmod)

moesp__zige:addSkill(emo__heli)

local emo__yange = fk.CreateTriggerSkill{
  name = "emo__yange",
  anim_type = "offensive",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 then
      return true
    end
  end,
  on_cost = function(self, event, target, player, data)
    local n = 0
    for _, move in ipairs(data) do
      if move.from == player.id and move.moveReason ~= fk.ReasonUse then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea == Card.PlayerHand then
            n = n + 1
          end
        end
      end
    end
    if n == 0 then return false end
    player.room:setPlayerMark(player, "emo__yange_num", n)
    local success, dat = player.room:askForUseActiveSkill(player, "emo__yange_active", "#emo__yange-use:::"..n)
    if success then
      self.cost_data = dat
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local dat = self.cost_data
    local use = {
      from = player.id,
      tos = table.map(dat.targets, function (id) return {id} end),
      card = Fk:cloneCard(player:getMark("emo__yange_name")),
    }
    use.card.skillName = self.name
    room:useCard(use)
  end,
}
local emo__yange_active = fk.CreateActiveSkill{
  name = "emo__yange_active",
  interaction = function()
    local names, all_names = {} , {}
    for _, id in ipairs(Fk:getAllCardIds()) do
      local card = Fk:getCardById(id)
      if card:isCommonTrick() and not card.is_derived and not table.contains(all_names, card.name) then
        table.insert(all_names, card.name)
        local to_use = Fk:cloneCard(card.name)
        if Self:canUse(to_use) and not Self:prohibitUse(to_use) then
          local x = 0
          if to_use.multiple_targets and to_use.skill:getMinTargetNum() == 0 then -- for AOE
            for _, p in ipairs(Fk:currentRoom().alive_players) do
              if not Self:isProhibited(p, card) and card.skill:modTargetFilter(p.id, {}, Self, card, true) then
                x = x + 1
              end
            end
          end
          if x <= Self:getMark("emo__yange_num") then
            table.insert(names, card.name)
          end
        end
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names, all_choices = all_names}
  end,
  card_num = 0,
  min_target_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = function (self, to_select, selected, selected_cards, card, extra_data, player)
    if self.interaction.data == nil then return false end
    local to_use = Fk:cloneCard(self.interaction.data)
    if not to_use.skill:targetFilter(to_select, selected, selected_cards, to_use, extra_data, player) then return false end
    if (#selected == 0 or to_use.multiple_targets) and
    player:isProhibited(Fk:currentRoom():getPlayerById(to_select), to_use) then return false end
    if to_use.multiple_targets then
      if #selected >= player:getMark("emo__yange_num") then return false end
      if to_use.skill:getMaxTargetNum(player, to_use) == 1 then
        local x = 0
        for _, p in ipairs(Fk:currentRoom().alive_players) do
          if p.id == to_select or (not player:isProhibited(p, to_use)
          and to_use.skill:modTargetFilter(p.id, {to_select}, player, to_use, true)) then
            x = x + 1
          end
        end
        if x > player:getMark("emo__yange_num") then return false end
      end
    end
    return true
  end,
  feasible = function(self, selected, selected_cards, player)
    if self.interaction.data == nil then return false end
    local to_use = Fk:cloneCard(self.interaction.data)
    return to_use.skill:feasible(selected, selected_cards, player, to_use)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:setPlayerMark(player, "emo__yange_name", self.interaction.data)
  end,
}
Fk:addSkill(emo__yange_active)

moesp__zige:addSkill(emo__yange)


Fk:loadTranslationTable{
  ["moesp__zige"] = "紫歌",
  ["designer:moesp__zige"] = "祭祀",
  
  ["emo__qianfei"] = "潜绯",
  [":emo__qianfei"] = "①一名角色于其回合内使用的第一张有目标角色的黑色牌结算后，你可以弃置一张牌并选一项：1.令此牌额外结算一次；2.令一个目标回复1点体力；②摸牌阶段，你可额外摸X张牌（X为手牌数小于你的角色数）。",
  ["#emo__qianfei-recover"] = "潜绯：令一个目标回复1点体力；“取消”：令%arg再结算一次",
  ["#emo__qianfei-invoke"] = "潜绯：可弃一张牌，令 %dest 使用的 %arg 额外结算或一个目标回复体力",
  ["#emo__qianfei-draw"] = "潜绯：可额外摸 %arg 张牌",

  ["emo__heli"] = "鹤唳",
  [":emo__heli"] = "你的回合内限一次，当你使用一张基本牌或普通锦囊牌时，你可以令之失效并执行两项：1.卜算2并摸两张牌；2.本回合使用牌无距离和次数限制；3.回复1点体力且本回合手牌上限无限；4.令一名其他角色交给你一张手牌且你下一张伤害牌无法响应。",
  ["emo__heli_draw"] = "卜算2并摸两张牌",
  ["emo__heli_limit"] = "本回合使用牌无距离和次数限制",
  ["emo__heli_recover"] = "回复1点体力且本回合手牌上限无限",
  ["emo__heli_give"] = "令其他角色给你一张牌,你下一张伤害牌无法响应",
  ["#emo__heli-choose"] = "鹤唳：令一名其他角色交给你一张手牌",
  ["#emo__heli-give"] = "鹤唳：交给 %src 一张手牌",
  ["@@emo__heli_damage"] = "鹤唳 无法响应",
  ["@@emo__heli_limit-turn"] = "鹤唳 牌无限制",

  ["emo__yange"] = "燕歌",
  [":emo__yange"] = "每回合限一次，当你不因使用而失去手牌时，你可以视为使用一张目标不大于X的普通锦囊牌（X为失去的牌数）。",
  ["#emo__yange-use"] = "燕歌：视为使用一张目标不大于 %arg 的普通锦囊牌",
  ["emo__yange_active"] = "燕歌",
}

local moesp__jiaxu = General(extension, "moesp__jiaxu", "moe", 3, 3, General.Female)
moesp__jiaxu.subkingdom = "qun"

local emo__mingshi = fk.CreateTriggerSkill{
  name = "emo__mingshi",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.RoundStart, fk.Damage},
  can_trigger = function(self, event, target, player, data)
    if event == fk.RoundStart then
      return player:hasSkill(self)
    else
      return player:hasSkill(self) and target and target.id == player:getMark(self.name)
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.RoundStart then
      local targets = room:getOtherPlayers(player)
      if #targets == 0 then return end
      local toId = #targets == 1 and targets[1].id or
      room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__mingshi-choose", self.name, false)[1]
      local to = room:getPlayerById(toId)
      local old = room:getPlayerById(player:getMark(self.name))
      room:setPlayerMark(player, self.name, to.id)
      room:setPlayerMark(player, "@emo__mingshi", to.general)
      if old and old ~= to and not old:isNude() then
        local id = room:askForCardChosen(player, old, "he", self.name)
        room:obtainCard(player, id, false, fk.ReasonPrey)
        if not player:isNude() and not to.dead then
          local card = room:askForCard(player, 1, 1, true, self.name, false, ".", "#emo__mingshi-give:"..to.id)
          room:obtainCard(to, card[1], false, fk.ReasonGive, player.id, self.name)
        end
      end
    else
      local lord = room:getPlayerById(player:getMark(self.name))
      player:drawCards(2, self.name)
      if not player:isKongcheng() and not lord.dead then
        local cards = room:askForCard(player, 1, player:getHandcardNum(), false, self.name, false, ".", "#emo__mingshi-give2:"..lord.id)
        room:obtainCard(lord, cards, false, fk.ReasonGive, player.id, self.name)
      end
    end
  end,
}

moesp__jiaxu:addSkill(emo__mingshi)

local emo__duce = fk.CreateActiveSkill{
  name = "emo__duce",
  anim_type = "offensive",
  card_num = 0,
  card_filter = Util.FalseFunc,
  min_target_num = 1,
  target_filter = function (self, to_select, selected)
    return #selected < Self:getHandcardNum() and to_select ~= Self.id 
    and not Self:isProhibited(Fk:currentRoom():getPlayerById(to_select), Fk:cloneCard("wd_poison__slash"))
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0 and not player:isKongcheng()
    and not player:prohibitUse(Fk:cloneCard("wd_poison__slash"))
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:throwAllCards("h")
    local tos = table.map(effect.tos, Util.Id2PlayerMapper)
    room:useVirtualCard("wd_poison__slash", nil, player, tos, self.name, true)
  end,
}

local emo__duce_delay = fk.CreateTriggerSkill{
  name = "#emo__duce_delay",
  mute = true,
  events = {fk.Damage, fk.CardEffectCancelledOut},
  can_trigger = function(self, event, target, player, data)
    if event == fk.Damage then
      return data.card and table.contains(data.card.skillNames, "emo__duce") and target == player and not player.dead
    else
      return table.contains(data.card.skillNames, "emo__duce") and target == player and not player.dead
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      player:drawCards(2, "emo__duce")
      if not player.dead and player:isWounded() then
        room:recover { num = 1, skillName = "emo__duce", who = player, recoverBy = player}
      end
    else
      room:loseHp(player, 1, "emo__duce")
      if not player.dead then
        player:turnOver()
      end
    end
  end,
}
emo__duce:addRelatedSkill(emo__duce_delay)

moesp__jiaxu:addSkill(emo__duce)


local emo__weimu = fk.CreateTriggerSkill{
  name = "emo__weimu",
  events = {fk.EventPhaseChanging, fk.DamageInflicted},
  anim_type = "defensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if event == fk.EventPhaseChanging then
      return player:hasSkill(self) and target == player and player.hp == player.maxHp and data.to == Player.Discard
    else
      return player:hasSkill(self) and target == player and not player.faceup
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.EventPhaseChanging then
      player:skip(data.to)
      return true
    else
      data.damage = data.damage - 1
    end
  end,
}

local emo__weimu_prohibit = fk.CreateProhibitSkill{
  name = "#emo__weimu_prohibit",
  is_prohibited = function(self, from, to, card)
    return to:hasSkill("emo__weimu") and ((card.trueName == "slash" and card.color == Card.NoColor) or (card.type == Card.TypeTrick and card.color == Card.Black))
  end,
}
emo__weimu:addRelatedSkill(emo__weimu_prohibit)

moesp__jiaxu:addSkill(emo__weimu)

Fk:loadTranslationTable{
  ["moesp__jiaxu"] = "萌贾文和",
  ["designer:moesp__jiaxu"] = "贾文和",
  
  ["emo__mingshi"] = "明势",
  [":emo__mingshi"] = "锁定技，每轮开始时，你标记一名其他角色为你的“君”，若你此前已有“君”，你获得其一张牌，然后交给新的“君”一张牌。每当你的“君”造成伤害后，你摸两张牌，然后交给其至少一张手牌。",
  ["#emo__mingshi-choose"] = "明势：你标记一名其他角色为你的“君”",
  ["@emo__mingshi"] = "君",
  ["#emo__mingshi-give"] = "明势：交给 %src 一张牌",
  ["#emo__mingshi-give2"] = "明势：交给 %src 至少一张手牌",

  ["emo__duce"] = "毒策",
  [":emo__duce"] = "出牌阶段限一次，你可以弃置所有手牌，视为对至多等量名其他角色使用一张无距离和次数限制的毒【杀】，每当此【杀】造成伤害后，你摸两张牌并回复一点体力；此【杀】被抵消时，你失去1点体力并翻面。",

  ["emo__weimu"] = "帷幕",
  [":emo__weimu"] = "锁定技，无色【杀】和黑色锦囊牌不能指定你为目标；若你未受伤，你跳过弃牌阶段；若你背面朝上，你受到的伤害-1。",
}

local moesp__christina = General(extension, "moesp__christina", "moe", 4, 4, General.Female)

local emo__relie = fk.CreateTriggerSkill{
  name = "emo__relie",
  events = {fk.DamageCaused},
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and player.room:getTag("RoundCount") == 1
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage + 1
  end,
}
moesp__christina:addSkill(emo__relie)

local emo__shengyu = fk.CreateTriggerSkill{
  name = "emo__shengyu",
  mute = true,
  events = {fk.Damage, fk.TurnEnd},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      return event == fk.Damage or player:getMark("skill_charge") >= 4
    end
  end,
  on_cost = function(self, event, target, player, data)
    if event == fk.TurnEnd then
      return player.room:askForSkillInvoke(player, self.name, nil, "#emo__shengyu-invoke")
    end
    return true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    if event == fk.Damage then
      room:notifySkillInvoked(player, self.name, "offensive")
      player:broadcastSkillInvoke(self.name, 3)
      U.skillCharged(player, data.damage)
      room:setPlayerMark(player, "@@emo__coin", (player:getMark("@@emo__coin") + 1) % 2)
    else
      room:notifySkillInvoked(player, self.name, "drawcard")
      player:broadcastSkillInvoke(self.name, math.random(2))
      U.skillCharged(player, -4)
      local x = player.maxHp - player:getHandcardNum()
      if x > 0 then
        player:drawCards(x, self.name)
      end
      if not player.dead then
        player:gainAnExtraPhase(Player.Play, true)
      end
    end
  end,

  refresh_events = {fk.EventAcquireSkill, fk.EventLoseSkill},
  can_refresh = function(self, event, target, player, data)
    return data == self and target == player
  end,
  on_refresh = function(self, event, target, player, data)
    if event == fk.EventAcquireSkill then
      U.skillCharged(player, 1, 4)
    else
      U.skillCharged(player, -1, -4)
    end
  end,
}
moesp__christina:addSkill(emo__shengyu)

local emo__zengli = fk.CreateActiveSkill{
  name = "emo__zengli",
  anim_type = "support",
  card_num = 1,
  target_num = 1,
  prompt = function()
    return "#emo__zengli-prompt".. Self:getMark("@@emo__coin")
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type ~= Card.TypeBasic
    and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    local to = room:getPlayerById(effect.tos[1])
    if to.dead then return end
    if player:getMark("@@emo__coin") > 0 then
      room:addPlayerMark(to, "@emo__zengli")
    else
      local cards = table.filter(room.draw_pile, function (id)
        return not Fk:getCardById(id).is_damage_card
      end)
      if #cards > 0 then
        room:obtainCard(to, table.random(cards, 2), false, fk.ReasonPrey)
      end
    end
  end,
}

local emo__zengli_delay = fk.CreateTriggerSkill{
  name = "#emo__zengli_delay",
  events = {fk.CardUsing},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:getMark("@emo__zengli") > 0 and data.card.is_damage_card
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    data.additionalDamage = (data.additionalDamage or 0) + player:getMark("@emo__zengli")
    room:setPlayerMark(player, "@emo__zengli", 0)
  end,
}
emo__zengli:addRelatedSkill(emo__zengli_delay)

moesp__christina:addSkill(emo__zengli)

local emo__fenjie = fk.CreateActiveSkill{
  name = "emo__fenjie",
  anim_type = "offensive",
  card_num = 1,
  target_num = 0,
  prompt = function()
    return "#emo__fenjie-prompt".. Self:getMark("@@emo__coin")
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and Fk:getCardById(to_select).type == Card.TypeBasic
    and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead then return end
    if player:getMark("@@emo__coin") > 0 then
      U.askForUseVirtualCard(room, player, "slash", nil, self.name, nil, false, true, true, true)
    else
      local cards = table.filter(room.draw_pile, function (id)
        return Fk:getCardById(id).is_damage_card
      end)
      if #cards > 0 then
        room:obtainCard(player, table.random(cards, 2), false, fk.ReasonPrey)
      end
    end
  end,
}
moesp__christina:addSkill(emo__fenjie)


Fk:loadTranslationTable{
  ["moesp__christina"] = "克莉丝缇娜", -- 作者：晴天娃娃
  ["designer:moesp__christina"] = "晴天娃娃",
  
  ["emo__relie"] = "热烈",
  [":emo__relie"] = "锁定技，每当你造成伤害时，若为第一轮，此伤害+1。",

  ["emo__shengyu"] = "圣域",
  [":emo__shengyu"] = "蓄力技（1/4），①每当你造成伤害后，你获得等于伤害值的蓄力值，然后获得/失去“硬币”；②回合结束时，你可以消耗4点蓄力值，摸牌至体力上限并执行一个额外的出牌阶段。",
  ["#emo__shengyu-invoke"] = "圣域：你可以摸牌至体力上限，执行一个额外的出牌阶段",
  ["@@emo__coin"] = "硬币",

  ["emo__zengli"] = "赠礼",
  [":emo__zengli"] = "出牌阶段限一次，你可以弃置一张非基本牌并选择一名角色：若你有“硬币”，其使用的下一张伤害牌的伤害基数+1；若没有，其摸两张非伤害牌。",
  ["#emo__zengli_delay"] = "赠礼",
  ["@emo__zengli"] = "赠礼",
  ["#emo__zengli-prompt1"] = "令一名角色使用的下一张伤害牌的伤害基数+1",
  ["#emo__zengli-prompt0"] = "令一名角色摸两张非伤害牌",

  ["emo__fenjie"] = "分解",
  [":emo__fenjie"] = "出牌阶段限一次，你可以弃置一张基本牌：若你有“硬币”，视为使用一张不计入次数的【杀】；若没有，摸两张伤害牌。",
  ["#emo__fenjie-prompt1"] = "视为使用【杀】",
  ["#emo__fenjie-prompt0"] = "摸两张伤害牌",

  ["$emo__relie1"] = "愉悦吗",
  ["$emo__relie2"] = "去死吧",
  ["$emo__shengyu1"] = "喜欢疼痛的感觉吗",
  ["$emo__shengyu2"] = "乱数圣域",
  ["$emo__shengyu3"] = "盛宴开始",
  ["$emo__zengli1"] = "根本不够刺激",
  ["$emo__zengli2"] = "比想象中的有趣",
  ["$emo__fenjie1"] = "下次也让我好好享受吧",
  ["$emo__fenjie2"] = "看你能坚持到什么时候",
  ["~moesp__christina"] = "为何如此难堪……",
}

local moesp__xuenv = General(extension, "moesp__xuenv", "moe", 3, 3, General.Female)

local emo__youhuo = fk.CreateTriggerSkill{
  name = "emo__youhuo",
  anim_type = "control",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Start and target == player
    and table.find(player.room:getOtherPlayers(player), function (p) return not p:isNude() and p.gender ~= player.gender end)
  end,
  on_cost = function (self, event, target, player, data)
    local targets = table.filter(player.room:getOtherPlayers(player), function (p) return not p:isNude() and p.gender ~= player.gender end)
    local tos = player.room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 3, "#emo__youhuo-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local moves, types = {}, {}
    for _, pid in ipairs(self.cost_data) do
      local p = room:getPlayerById(pid)
      local gets = table.filter(p:getCardIds("he"), function (id)
        return table.every(types, function(_type) return _type ~= Fk:getCardById(id).type end)
      end)
      local get = #gets > 0 and table.random(gets) or table.random(p:getCardIds("he"))
      table.insertIfNeed(types, Fk:getCardById(get).type)
      table.insert(moves, {
        from = pid,
        ids = {get},
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonPrey,
        proposer = player.id,
      })
    end
    room:moveCards(table.unpack(moves))
  end
}
moesp__xuenv:addSkill(emo__youhuo)

local emo__bingren = fk.CreateTriggerSkill{
  name = "emo__bingren",
  anim_type = "offensive",
  events = {fk.PreCardUse},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.card.is_damage_card then
      return #player.room.logic:getEventsOfScope(GameEvent.UseCard, 1, function(e)
        local use = e.data[1]
        return use.from == player.id and not use.card.is_damage_card
      end, Player.HistoryTurn) == 0
    end
  end,
  on_use = function (self, event, target, player, data)
    data.extraUse = true
    data.disresponsiveList = table.map(player.room.alive_players, Util.IdMapper)
  end,
}

local emo__bingren_filter = fk.CreateFilterSkill{
  name = "#emo__bingren_filter",
  card_filter = function(self, card, player, isJudgeEvent)
    return player:hasSkill("emo__bingren") and card.name == "slash" and
    (table.contains(player.player_cards[Player.Hand], card.id) or isJudgeEvent)
  end,
  view_as = function(self, card)
    return Fk:cloneCard("ice__slash", card.suit, card.number)
  end,
}
emo__bingren:addRelatedSkill(emo__bingren_filter)

moesp__xuenv:addSkill(emo__bingren)


local emo__moejie = fk.CreateTriggerSkill{
  name = "emo__moejie",
  anim_type = "control",
  events = {fk.GameStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local targets = table.filter(room:getOtherPlayers(player), function (p) return p.gender ~= player.gender end)
    local tos = room:askForChoosePlayers(player, table.map(targets, Util.IdMapper), 1, 1, "#emo__moejie-choose", self.name, true)
    if #tos > 0 then
      self.cost_data = tos[1]
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(self.cost_data)
    room:setPlayerMark(to, "@@emo__moejie", 1)
    local mark = player:getTableMark("emo__moejie_target")
    table.insertIfNeed(mark, to.id)
    room:setPlayerMark(player, "emo__moejie_target", mark)
    room:broadcastProperty(player, "MaxCards")
  end
}
local emo__moejie_maxcards = fk.CreateMaxCardsSkill{
  name = "#emo__moejie_maxcards",
  correct_func = function(self, player)
    if player:getMark("emo__moejie") then
      local n = 0
      for _, pid in ipairs(player:getTableMark("emo__moejie_target")) do
        n = n + Fk:currentRoom():getPlayerById(pid):getHandcardNum()
      end
      return n
    end
  end,
}
emo__moejie:addRelatedSkill(emo__moejie_maxcards)

local emo__moejie_delay = fk.CreateTriggerSkill{
  name = "#emo__moejie_delay",
  anim_type = "drawcard",
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:usedSkillTimes(self.name, Player.HistoryTurn) < 3 then
      local mark = player:getTableMark("emo__moejie_target")
      if table.find(mark, function(pid) return player.room:getPlayerById(pid):isAlive() end) then
        for _, move in ipairs(data) do
          if (move.moveReason == fk.ReasonDiscard or move.moveReason == fk.ReasonPrey) then
            if move.from and move.proposer == player.id and move.from ~= player.id then
              for _, info in ipairs(move.moveInfo) do
                if info.fromArea == Card.PlayerHand or info.fromArea == Card.PlayerEquip then
                  return true
                end
              end
            end
          end
        end
      end
    end
  end,
  on_trigger = function(self, event, target, player, data)
    local room = player.room
    local tos = table.filter(player:getTableMark("emo__moejie_target"), function(pid) return room:getPlayerById(pid):isAlive() end)
    room:sortPlayersByAction(tos)
    for _, pid in ipairs(tos) do
      local skill_target = room:getPlayerById(pid)
      if not player:hasSkill(self) then break end
      if not skill_target.dead then
        self:doCost(event, skill_target, player, data)
      end
    end
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__moejie-invoke:"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player.room:doIndicate(player.id, {target.id})
    target:drawCards(1, self.name)
  end,
}
emo__moejie:addRelatedSkill(emo__moejie_delay)

moesp__xuenv:addSkill(emo__moejie)


Fk:loadTranslationTable{
  ["moesp__xuenv"] = "雪女", -- 作者：武德何在
  ["designer:moesp__xuenv"] = "武德何在",
  
  ["emo__youhuo"] = "诱惑",
  [":emo__youhuo"] = "准备阶段，你可以选择至多三名异性角色，同时获得这些角色各随机一张牌（优先获得类型不同的牌）。",
  ["#emo__youhuo-choose"] = "诱惑：获得至多三名异性角色各一张牌",

  ["emo__bingren"] = "冰刃",
  [":emo__bingren"] = "锁定技，当你使用伤害牌时，若你本回合未使用过非伤害牌，此牌无法响应且不计入次数。你的普通【杀】视为冰【杀】。",
  ["#emo__bingren_filter"] = "冰刃",

  ["emo__moejie"] = "魔戒",
  [":emo__moejie"] = "游戏开始时，你可以令一名异性角色获得“魔戒”标记，你的手牌上限+X（X为其手牌数）。每回合限三次，每当你获得或弃置其他角色的牌时，你可以令该角色摸一张牌。",
  ["#emo__moejie-choose"] = "魔戒：你可以令一名异性角色获得“魔戒”标记",
  ["@@emo__moejie"] = "魔戒",
  ["#emo__moejie_delay"] = "魔戒",
  ["#emo__moejie-invoke"] = "魔戒：你可以令 %src 摸一张牌",
}

local moesp__qingtianwawa = General(extension, "moesp__qingtianwawa", "moe", 1, 1, General.Female)

local emo__fuhe = fk.CreateTriggerSkill{
  name = "emo__fuhe",
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  events = {fk.AfterCardsMove},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) < 10 then
      if table.find(player.room:getOtherPlayers(player), function(p) return p:getHandcardNum() >= player:getHandcardNum() end) then
        for _, move in ipairs(data) do
          if move.to ~= player.id and move.toArea == Card.PlayerHand then
            return true
          end
        end
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    player:drawCards(1, self.name)
  end,
}

local emo__fuhe_trigger = fk.CreateTriggerSkill{
  name = "#emo__fuhe_trigger",
  anim_type = "negative",
  frequency = Skill.Compulsory,
  events = {fk.CardUseFinished},
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and target == player and player.phase == Player.Play then
      return data.card.type ~= Card.TypeEquip
    end
  end,
  on_use = function(self, event, target, player, data)
    player:endPlayPhase()
  end,
}
emo__fuhe:addRelatedSkill(emo__fuhe_trigger)

moesp__qingtianwawa:addSkill(emo__fuhe)

local emo__rechen = fk.CreateTriggerSkill{
  name = "emo__rechen",
  anim_type = "control",
  events = {fk.DamageInflicted},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and (player == target or player:distanceTo(target) == 1)
    and #player:getCardIds("he") > 1 and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local cards = room:askForDiscard(player, 2, 2, true, self.name, true, ".", "#emo__rechen-card::"..target.id, true)
    if #cards > 0 then
      local n = room:askForChoice(player, {"+1", "-1"}, self.name)
      self.cost_data = {cards, tonumber(n)}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data[1], self.name, player, player)
    data.damage = data.damage + self.cost_data[2]
  end,
}

moesp__qingtianwawa:addSkill(emo__rechen)

local emo__zhuojin = fk.CreateTriggerSkill{
  name = "emo__zhuojin",
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.phase == Player.Start and player:getHandcardNum() > 1
  end,
  on_cost = function(self, event, target, player, data)
    local room = player.room
    local success, dat = room:askForUseViewAsSkill(player, "emo__zhuojin_active", "#emo__zhuojin-card", true, {bypass_times = true})
    if success and dat then
      local card = Fk:cloneCard(dat.interaction)
      card.skillName = self.name
      local use = {
        from = player.id,
        tos = table.map(dat.targets, function(p) return {p} end),
        card = card,
        extraUse = true,
      }
      self.cost_data = {dat.cards, use}
      return true
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:throwCard(self.cost_data[1], self.name, player, player)
    local use = self.cost_data[2]
    if use.card:isCommonTrick() then
      local mark = player:getTableMark("emo__zhuojin_used")
      table.insert(mark, use.card.name)
      room:setPlayerMark(player, "emo__zhuojin_used", mark)
    else
      room:setPlayerMark(player, "emo__zhuojin_slash-round", 1)
    end
    room:useCard(use)
  end,
}
local emo__zhuojin_active = fk.CreateViewAsSkill{
  name = "emo__zhuojin_active",
  card_num = 2,
  interaction = function()
    local names = {}
    if Self:getMark("emo__zhuojin_slash-round") == 0 then
      table.insert(names, "slash")
    end
    local mark = Self:getTableMark("emo__zhuojin_used")
    for name, _ in pairs(Fk.all_card_types) do
      local card = Fk:cloneCard(name)
      if not table.contains(mark, card.name) and not card.is_derived 
        and card:isCommonTrick() and  not table.contains(Fk:currentRoom().disabled_packs, card.package.name)
        and not Self:prohibitUse(card) and Self:canUse(card, {bypass_times = true}) then
        table.insertIfNeed(names, card.name)
      end
    end
    return UI.ComboBox {choices = names}
  end,
  card_filter = function(self, to_select, selected)
    return #selected < 2 and table.contains(Self.player_cards[Player.Hand], to_select)
    and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  view_as = function(self, cards)
    if #cards ~= 2 or not self.interaction.data then return nil end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = "emo__zhuojin"
    return c
  end,
}
Fk:addSkill(emo__zhuojin_active)

moesp__qingtianwawa:addSkill(emo__zhuojin)

local emo__chongzhen = fk.CreateTriggerSkill{
  name = "emo__chongzhen",
  events = {fk.EnterDying},
  anim_type = "defensive",
  frequency = Skill.Limited,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target == player and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    and (player:hasSkill("emo__fuhe",  true) or player:hasSkill("emo__rechen",  true) or player:hasSkill("emo__zhuojin",  true))
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__chongzhen-invoke")
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local skills = table.filter({"emo__fuhe","emo__rechen","emo__zhuojin"}, function (s)
      return player:hasSkill(s,  true)
    end)
    if #skills == 0 then return end
    local choices = room:askForChoices(player, skills, 1, #skills, self.name, "#emo__chongzhen-choice", false, true)
    room:handleAddLoseSkills(player, "-"..table.concat(choices, "|-"), nil)
    room:changeMaxHp(player, #choices - 1)
    if not player.dead and player:isWounded() then
      room:recover { num = player.maxHp - player.hp, skillName = self.name, who = player, recoverBy = player}
    end
    if player.dead then return end
    local officialPackage = {"jsrg", "mobile", "mougong", "ol", "overseas", "sp", "tenyear", "offline", "standard_ex"}
    local generals = {}
    for _, name in pairs(room.general_pile) do
      local general = Fk.generals[name]
      if table.contains(officialPackage, general.package.extensionName) then
        table.insert(generals, name)
      end
    end
    if #generals == 0 then return end
    generals = table.random(generals, 5)
    local general_skills, all_skills = {}, {}
    for _, g in ipairs(generals) do
      local list = {}
      for _, s in ipairs(Fk.generals[g]:getSkillNameList()) do
        if not player:hasSkill(s, true) and not table.contains(all_skills, s) then
          table.insert(list, s)
          table.insert(all_skills, s)
        end
      end
      table.insert(general_skills, list)
    end
    if #all_skills == 0 then return end
    local result = player.room:askForCustomDialog(player, self.name,
    "packages/tenyear/qml/ChooseGeneralSkillsBox.qml", {
      generals, general_skills, 1, #choices, "#emo__chongzhen-skill:::"..#choices, true
    })
    local chosen_skills = (result ~= "") and json.decode(result) or table.random(all_skills, #choices)
    room:handleAddLoseSkills(player, table.concat(chosen_skills, "|"))
  end,
}
moesp__qingtianwawa:addSkill(emo__chongzhen)

Fk:loadTranslationTable{
  ["moesp__qingtianwawa"] = "晴天娃娃",
  ["designer:moesp__qingtianwawa"] = "不明觉厉de", -- 作者：不明觉厉de
  
  ["emo__fuhe"] = "附和",
  [":emo__fuhe"] = "锁定技，①你于出牌阶段使用非装备牌后，结束此阶段。②每回合限十次，每当其他角色获得牌时，若你手牌数不为唯一最大，你摸一张牌。",
  ["#emo__fuhe_trigger"] = "附和",

  ["emo__rechen"] = "热忱",
  [":emo__rechen"] = "每回合一次，每当你距离1以内的角色受到伤害时，你可以弃置两张牌，令此伤害+1或-1。",
  ["#emo__rechen-card"] = "热忱：你可以弃置两张牌，令 %dest 受到的伤害+1或-1",

  ["emo__zhuojin"] = "捉襟",
  [":emo__zhuojin"] = "一名角色的准备阶段，你可以弃置两张手牌，并视为使用一张普通【杀】或任意普通锦囊牌（【杀】每轮限一次，锦囊牌每牌名限一次）。",
  ["#emo__zhuojin-card"] = "捉襟：可以弃置两张手牌，并视为使用一张普通【杀】或任意普通锦囊牌",
  ["emo__zhuojin_active"] = "捉襟",

  ["emo__chongzhen"] = "重振",
  [":emo__chongzhen"] = "限定技，当你进入濒死状态时，你可以失去〖附和〗/〖热忱〗/〖捉襟〗中至少一个技能，增加X-1点体力上限，再回复体力至上限，然后从随机5个武将牌中获得至多X个技能（X为你失去的技能数）。",
  ["#emo__chongzhen-invoke"] = "重振：你可以失去“附和”、“热忱”、“捉襟”中任意个",
  ["#emo__chongzhen-choice"] = "重振：选择失去的技能，增加等量体力上限，回复体力至上限，获得等量新技能",
  ["#emo__chongzhen-skill"] = "重振：选择 %arg 个技能获得",

  ["$emo__chongzhen1"] = "我是不会放弃的",
  ["$emo__chongzhen2"] = "我应该也可以的",
}

local moesp__thesilent = General(extension, "moesp__thesilent", "moe", 3, 3, General.Female)
moesp__thesilent.subkingdom = "wu"

local emo__lingqiao = fk.CreateTriggerSkill{
  name = "emo__lingqiao",
  anim_type = "control",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseChanging},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self) and data.to == Player.Judge
  end,
  on_use = function(self, event, target, player, data)
    player:skip(Player.Judge)
    return true
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function(self, event, target, player, data)
    return player.room.current == player and player:hasSkill(self, true) and #player:getTableMark("@emo__lingqiao-turn") < 4
  end,
  on_refresh = function(self, event, target, player, data)
    local mark = player:getTableMark("@emo__lingqiao-turn")
    for _, move in ipairs(data) do
      if move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if Fk:getCardById(info.cardId).suit ~= Card.NoSuit then
            table.insertIfNeed(mark, Fk:getCardById(info.cardId):getSuitString(true))
          end
        end
      end
    end
    player.room:setPlayerMark(player, "@emo__lingqiao-turn", mark)
    player.room:broadcastProperty(player, "MaxCards")
  end
}

local emo__lingqiao_maxcards = fk.CreateMaxCardsSkill{
  name = "#xxx_maxcards",
  correct_func = function(self, player)
    return player:hasSkill(emo__lingqiao) and #player:getTableMark("@emo__lingqiao-turn") or 0
  end,
}
emo__lingqiao:addRelatedSkill(emo__lingqiao_maxcards)

local emo__lingqiao_filter = fk.CreateFilterSkill{
  name = "#emo__lingqiao_filter",
  card_filter = function(self, card, player, isJudgeEvent)
    return card.type == Card.TypeTrick and card.number > 9
    and player:hasSkill(emo__lingqiao) and table.contains(player:getCardIds("h"), card.id)
  end,
  view_as = function(self, card)
    return Fk:cloneCard("ex_nihilo", card.suit, card.number)
  end,
}
emo__lingqiao:addRelatedSkill(emo__lingqiao_filter)

moesp__thesilent:addSkill(emo__lingqiao)

local emo__zaji = fk.CreateActiveSkill{
  name = "emo__zaji",
  anim_type = "drawcard",
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and Self.id ~= to_select and not Fk:currentRoom():getPlayerById(to_select):isNude()
  end,
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    player:drawCards(3, self.name)
    local cards = table.filter(player:getCardIds("he"), function (id)
      return not player:prohibitDiscard(Fk:getCardById(id))
    end)
    if #cards > 0 then
      local throw = table.random(cards)
      room:throwCard({throw}, self.name, player, player)
      if Fk:getCardById(throw).type == Card.TypeEquip then
        player:setSkillUseHistory(self.name, 0, Player.HistoryPhase)
      end
    end
  end,
}
moesp__thesilent:addSkill(emo__zaji)

local emo__daowu = fk.CreateTriggerSkill{
  name = "emo__daowu",
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  events = {fk.EventPhaseStart},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and player.phase == Player.Finish then
      local num = 0
      player.room.logic:getEventsOfScope(GameEvent.MoveCards, 1, function(e)
        for _, move in ipairs(e.data) do
          if move.toArea == Card.DiscardPile then
            num = num + #move.moveInfo
          end
        end
        return false
      end, Player.HistoryTurn)
      num = num // 6
      if num > 0 then
        self.cost_data = num
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = self.cost_data
    local cards = room:getCardsFromPileByRule("stab__slash", num, "allPiles")
    for i = 1, num - #cards do
      table.insert(cards, room:printCard("stab__slash", Card.Spade, math.random(6,9)).id)
    end
    room:obtainCard(player, cards, false, fk.ReasonPrey)
  end,
}

local emo__daowu_targetmod = fk.CreateTargetModSkill{
  name = "#emo__daowu_targetmod",
  residue_func = function(self, player, skill, scope, card)
    if player:hasSkill(emo__daowu) and card and card.name == "slash" and scope == Player.HistoryPhase then
      return -1
    end
  end,
  bypass_times = function(self, player, skill, scope, card)
    return player:hasSkill(emo__daowu) and card and card.name ~= "slash" and card.trueName == "slash"
  end,
}
emo__daowu:addRelatedSkill(emo__daowu_targetmod)

moesp__thesilent:addSkill(emo__daowu)


Fk:loadTranslationTable{
  ["moesp__thesilent"] = "静默猎手",
  ["designer:moesp__thesilent"] = "Kasa",
  
  ["emo__lingqiao"] = "灵巧",
  [":emo__lingqiao"] = "锁定技，跳过你的判定阶段；你的点数大于9的锦囊牌视为【无中生有】；你的手牌上限+X（X为你的回合内进入弃牌堆的花色数）。",
  ["@emo__lingqiao-turn"] = "灵巧",
  ["#emo__lingqiao_filter"] = "灵巧",

  ["emo__zaji"] = "杂技",
  [":emo__zaji"] = "出牌阶段限一次，你可以摸三张牌然后随机弃置一张牌，若弃置的牌为装备牌，此技能视为未发动。",

  ["emo__daowu"] = "刀舞",
  [":emo__daowu"] = "锁定技，结束阶段，本回合每有六张牌进入弃牌堆，你获得一张刺【杀】；你使用普通【杀】次数上限-1，使用特殊【杀】无次数限制。",
}

local moesp__shenhuxiaoniao = General(extension, "moesp__shenhuxiaoniao", "moe", 3, 3, General.Female)

local emo__yinwu = fk.CreateTriggerSkill{
  name = "emo__yinwu",
  events = {fk.CardUseFinished},
  derived_piles = "yinwu_monster",
  can_trigger = function(self, event, target, player, data)
    if player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) == 0 and not data.damageDealt 
    and U.isPureCard(data.card) and (data.card.type == Card.TypeBasic or data.card:isCommonTrick()) 
    and player.room:getCardArea(data.card) == Card.Processing then
      return table.every(player:getPile("yinwu_monster"), function (id)
        return Fk:getCardById(id).suit ~= Fk:getCardById(data.card.id).suit
      end)
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__yinwu-invoke:::"..data.card:toLogString())
  end,
  on_use = function(self, event, target, player, data)
    player:addToPile("yinwu_monster", data.card, true, self.name)
  end,
}
moesp__shenhuxiaoniao:addSkill(emo__yinwu)

local emo__yumos = fk.CreateViewAsSkill{
  name = "emo__yumos",
  card_num = 1,
  pattern = ".",
  interaction = function()
    local names = {}
    if Fk.currentResponsePattern == nil then table.insert(names, "bogus_flower") end
    for _, id in ipairs(Self:getPile("yinwu_monster")) do
      local card = Fk:cloneCard(Fk:getCardById(id).name)
      if ((Fk.currentResponsePattern == nil and Self:canUse(card)) or
        (Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(card))) then
        table.insertIfNeed(names, card.name)
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  view_as = function(self, cards)
    if #cards ~= 1 or not self.interaction.data then return nil end
    local c = Fk:cloneCard(self.interaction.data)
    c.skillName = self.name
    Self:setMark("emo__yumos_throw", cards[1])
    return c
  end,
  card_filter = function(self, to_select, selected)
    return #selected == 0 and not Self:prohibitDiscard(Fk:getCardById(to_select))
  end,
  before_use = function(self, player, use)
    local room = player.room
    local to_throw = player:getMark("emo__yumos_throw")
    if to_throw == 0 then return end
    local cards = player:getPile("yinwu_monster")
    if use.card.name ~= "bogus_flower" then
      cards = table.filter(cards, function(id) return Fk:getCardById(id).name == use.card.name end)
    end
    local to_use
    if #cards == 0 then
      return 
    elseif #cards == 1 then
      to_use = cards[1]
    else
      to_use = room:askForCardChosen(player, player, { card_data = { { "yinwu_monster", cards }  } }, self.name, "#emo__yumos-remove")
    end
    room:moveCards({
      from = player.id,
      ids = {to_throw},
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonDiscard,
      proposer = player.id,
      skillName = self.name,
    },{
      from = player.id,
      ids = {to_use},
      moveInfo = {{cardId = to_use, fromArea = Card.PlayerSpecial, fromSpecialName = "yinwu_monster" }},
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonPutIntoDiscardPile,
      proposer = player.id,
      skillName = self.name,
    })
    if player.dead then return end
    if Fk:getCardById(to_throw).suit == Fk:getCardById(to_use).suit then
      use.extra_data = use.extra_data or {}
      use.extra_data.emo__yumos_extraTar = true
    end
    if Fk:getCardById(to_throw).type == Fk:getCardById(to_use).type then
      player:drawCards(1, self.name)
    end
  end,
  enabled_at_play = function(self, player)
    if not player:isNude() and #player:getPile("yinwu_monster") > 0 then
      local flower = Fk:cloneCard("bogus_flower")
      if player:canUse(flower) and not player:prohibitUse(flower) then return true end
      for _, id in ipairs(player:getPile("yinwu_monster")) do
        local card = Fk:cloneCard(Fk:getCardById(id).name)
        if player:canUse(card) and not player:prohibitUse(card) then
          return true
        end
      end
    end
  end,
  enabled_at_response = function (self, player, response)
    if not player:isNude() and #player:getPile("yinwu_monster") > 0 and not response and Fk.currentResponsePattern then
      for _, id in ipairs(player:getPile("yinwu_monster")) do
        local card = Fk:cloneCard(Fk:getCardById(id).name)
        if Exppattern:Parse(Fk.currentResponsePattern):match(card) then
          return true
        end
      end
    end
  end,
}
local emo__yumos_delay = fk.CreateTriggerSkill{
  name = "#emo__yumos_delay",
  mute = true,
  events = {fk.AfterCardTargetDeclared},
  can_trigger = function(self, event, target, player, data)
    return target == player and not player.dead and data.extra_data and data.extra_data.emo__yumos_extraTar
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local targets = U.getUseExtraTargets(room, data, false, false)
    if #targets > 0 then
      local tos = player.room:askForChoosePlayers(player, targets, 1, 1, "#emo__yumos-target:::"..data.card.name, self.name, true)
      if #tos > 0 then
        table.insert(data.tos, tos)
        room:sendLog{
          type = "#AddTargetsBySkill",
          from = player.id,
          to = tos,
          arg = self.name,
          arg2 = data.card:toLogString()
        }
      end
    end
  end,
}
emo__yumos:addRelatedSkill(emo__yumos_delay)

moesp__shenhuxiaoniao:addSkill(emo__yumos)

local emo__liaosi = fk.CreateTriggerSkill{
  name = "emo__liaosi",
  events = {fk.EnterDying},
  frequency = Skill.Limited,
  anim_type = "support",
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self) and target.dying and not target.dead and not target:isNude()
    and #player:getPile("yinwu_monster") > 0 and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
    and not player:prohibitUse(Fk:cloneCard("bogus_flower")) and not player:isProhibited(target, Fk:cloneCard("bogus_flower"))
  end,
  on_cost = function(self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__liaosi-invoke::"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local tos = player:getTableMark("emo__liaosi_target")
    table.insertIfNeed(tos, target.id)
    room:setPlayerMark(player, "emo__liaosi_target", tos)
    local cards = player:getPile("yinwu_monster")
    room:moveCards({
      from = player.id,
      ids = cards,
      toArea = Card.DiscardPile,
      moveReason = fk.ReasonPutIntoDiscardPile,
      proposer = player.id,
      skillName = self.name,
    })
    for i = 1, #cards do
      if target.dead or player.dead then break end
      local card = Fk:cloneCard("bogus_flower")
      card.skillName = self.name
      if player:prohibitUse(Fk:cloneCard("bogus_flower")) or player:isProhibited(target, Fk:cloneCard("bogus_flower")) then break end
      room:useCard({
        from = player.id,
        card = card,
        tos = {{target.id}},
        extra_data = {emo__liaosi_target = target.id},
      })
      room:delay(200)
    end
    if target.dead then return end
    local num = #target:getTableMark("@emo__liaosi-phase")
    room:setPlayerMark(target, "@emo__liaosi-phase", 0)
    room:recover({ who = target,  num = math.min(num, target.maxHp-target.hp), recoverBy = player, skillName = self.name })
  end,

  refresh_events = {fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if player.dead then return false end
    local e = player.room.logic:getCurrentEvent():findParent(GameEvent.CardEffect)
    if e then
      local use = e.data[1]
      if use.card.name == "bogus_flower" and use.extra_data and use.extra_data.emo__liaosi_target == player.id then
        for _, move in ipairs(data) do
          if move.moveReason == fk.ReasonDiscard and move.from == player.id then
            return true
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local mark = player:getTableMark("@emo__liaosi-phase")
    for _, move in ipairs(data) do
      if move.moveReason == fk.ReasonDiscard and move.from == player.id then
        for _, info in ipairs(move.moveInfo) do
          table.insertIfNeed(mark, Fk:getCardById(info.cardId):getSuitString(true))
        end
      end
    end
    player.room:setPlayerMark(player, "@emo__liaosi-phase", mark)
  end,
}

local emo__liaosi_delay = fk.CreateTriggerSkill{
  name = "#emo__liaosi_delay",
  events = {fk.TurnStart},
  anim_type = "negative",
  can_trigger = function(self, event, target, player, data)
    return player:getMark("@@emo__liaosi_losehp") > 0 and target == player and not player.dead
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    player.room:loseHp(player, 1, "emo__liaosi")
  end,

  refresh_events = {fk.Death},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("emo__liaosi_target") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    for _, pid in ipairs(player:getMark("emo__liaosi_target")) do
      player.room:setPlayerMark(player.room:getPlayerById(pid), "@@emo__liaosi_losehp", 1)
    end
  end,
}

emo__liaosi:addRelatedSkill(emo__liaosi_delay)
moesp__shenhuxiaoniao:addSkill(emo__liaosi)

local emo__jianbu = fk.CreateTriggerSkill{
  name = "emo__jianbu",
  events = {fk.GameStart, fk.EventAcquireSkill, fk.Deathed, fk.BeforeMaxHpChanged, fk.TurnEnd},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if (not player:hasSkill(self)) or (player.room:getTag("RoundCount") == nil)
    or player:usedSkillTimes(self.name, Player.HistoryPhase) > 10 then return false end
    local n = #player.room.alive_players
    if event == fk.BeforeMaxHpChanged then
      return target == player and (player.maxHp + data.num) ~= n
    elseif player.maxHp ~= n then
      if event == fk.EventAcquireSkill then
        return player == target and data == self
      else
        return true
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local n = #room.alive_players
    if event == fk.BeforeMaxHpChanged then
      data.num = n - player.maxHp
    else
      room:changeMaxHp(player, n - player.maxHp)
      room:broadcastProperty(player, "MaxCards")
    end
  end,
}

local emo__jianbu_maxcards = fk.CreateMaxCardsSkill{
  name = "#emo__jianbu_maxcards",
  fixed_func = function(self, player)
    if player:hasSkill("emo__jianbu") then
      return player.maxHp
    end
  end
}

emo__jianbu:addRelatedSkill(emo__jianbu_maxcards)
moesp__shenhuxiaoniao:addSkill(emo__jianbu)


Fk:loadTranslationTable{
  ["moesp__shenhuxiaoniao"] = "神户小鸟",
  ["designer:moesp__shenhuxiaoniao"] = "人社",
  
  ["emo__yinwu"] = "引物",
  [":emo__yinwu"] = "每回合限一次，当一张实体基本牌或普通锦囊牌结算结束后，若此牌没有造成伤害且与所有的“魔物”牌的花色均不同，你可以将其置于你的武将牌上，称为“魔物”。",
  ["yinwu_monster"] = "魔物",
  ["#emo__yinwu-invoke"] = "引物：你可以将 %arg 作为“魔物”牌置于武将牌上",

  ["emo__yumos"] = "驭魔",
  [":emo__yumos"] = "你可以弃置一张牌并移去一张“魔物”，视为使用一张【树上开花】或与此“魔物”同名的牌。若弃置的牌与此“魔物”：花色相同，以此法使用的牌可额外指定一个目标；类型相同，你摸一张牌。",
  ["#emo__yumos-remove"] = "驭魔：请移去一张“魔物”",
  ["#emo__yumos_delay"] = "驭魔",
  ["#emo__yumos-target"] = "驭魔：可以为 %arg 额外指定一个目标",

  ["emo__liaosi"] = "疗丝",
  [":emo__liaosi"] = "限定技，当一名角色进入濒死状态时，你可以移去所有“魔物”并视为对该角色使用等量张【树上开花】，然后令其回复X点体力（X为其以此法弃置牌的花色数）。你死亡后，该角色每回合开始时失去一点体力。",
  ["#emo__liaosi-invoke"] = "疗丝：你可以移去所有“魔物”并视为对 %dest 使用等量张【树上开花】",
  ["@emo__liaosi-phase"] = "疗丝",
  ["@@emo__liaosi_losehp"] = "疗丝",
  ["#emo__liaosi_delay"] = "疗丝",
  ["$emo__liaosi1"] = "",
  ["$emo__liaosi2"] = "",

  ["emo__jianbu"] = "键哺",
  [":emo__jianbu"] = "锁定技，你的体力上限与手牌上限基数等于存活角色数。",
}

local zhangchangpu = General(extension, "moesp__zhangchangpu", "moe", 3, 3, General.Female)
zhangchangpu.subkingdom = "wei"
local emo__yanjiao = fk.CreateActiveSkill{
  name = "emo__yanjiao",
  anim_type = "support",
  mute = true,
  card_num = 0,
  target_num = 1,
  prompt = "#emo__yanjiao",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) == 0
  end,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected)
    return #selected == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local target = room:getPlayerById(effect.tos[1])
    player:broadcastSkillInvoke(self.name, math.random(2))
    room:notifySkillInvoked(player, self.name)
    local num = math.min(6, player:getMark("@emo__yanjiao"))
    local n = 4 + num
    room:removePlayerMark(player, "@emo__yanjiao", num)
    local cards = room:getNCards(n)
    room:moveCards({
      ids = cards,
      toArea = Card.Processing,
      moveReason = fk.ReasonPut,
      skillName = self.name,
      proposer = player.id,
    })
    local data_table = {}
    for _, p in ipairs(room.players) do
      data_table[p.id] = {
        cards,
        "Group1",
        "Group2",
        p == target
      }
    end
    room:askForMiniGame(room.players, self.name, "yanjiao", data_table)
    local cardmap = json.decode(target.client_reply)
    local rest, pile1, pile2 = cards, {}, {}
    if #cardmap == 3 then
      rest, pile1, pile2 = cardmap[1], cardmap[2], cardmap[3]
    end
    local moveInfos = {}
    if #pile1 > 0 and #pile2 > 0 then
      player:skip(Player.Discard)
      local chosen = room:askForCardChosen(player, player,  { card_data = { {"Group1", pile1}, {"Group2", pile2}  } }, self.name, "#emo__yanjiao-choice")
      local get = table.contains(pile1, chosen) and pile1 or pile2
      table.insert(moveInfos, {
        ids = get,
        to = player.id,
        toArea = Card.PlayerHand,
        moveReason = fk.ReasonPrey,
        skillName = self.name,
        moveVisible = true,
      })
      local toId
      if target == player then
        local tos = room:askForChoosePlayers(player, table.map(room:getOtherPlayers(player), Util.IdMapper), 1, 1, "#emo__yanjiao-choose", self.name, true)
        if #tos > 0 then
          toId = tos[1]
        end
      else
        toId = target.id
      end
      local other = table.contains(pile2, chosen) and pile1 or pile2
      if toId then
        table.insert(moveInfos, {
          ids = other,
          to = toId,
          toArea = Card.PlayerHand,
          moveReason = fk.ReasonGive,
          skillName = self.name,
          moveVisible = true,
          proposer = player.id,
        })
      else
        table.insertTable(rest, other)
      end
    else
      -- 失败
      player:broadcastSkillInvoke(self.name, 3)
    end
    if #rest > 0 then
      table.insert(moveInfos, {
        ids = rest,
        toArea = Card.DiscardPile,
        moveReason = fk.ReasonPutIntoDiscardPile,
        proposer = player.id,
        skillName = self.name,
      })
    end
    room:moveCards(table.unpack(moveInfos))
  end,
}
zhangchangpu:addSkill(emo__yanjiao)

local emo__xingshen = fk.CreateTriggerSkill{
  name = "emo__xingshen",
  anim_type = "masochism",
  events = {fk.Damaged},
  on_trigger = function(self, event, target, player, data)
    self.cancel_cost = false
    for i = 1, data.damage do
      self:doCost(event, target, player, data)
      if self.cancel_cost or not player:hasSkill(self) then break end
    end
  end,
  on_cost = function (self, event, target, player, data)
    if player.room:askForSkillInvoke(player, self.name) then
      return true
    end
    self.cancel_cost = true
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:drawCards(2, self.name)
    if player.dead then return end
    room:addPlayerMark(player, "@emo__yanjiao", 2)
  end,
}
zhangchangpu:addSkill(emo__xingshen)

Fk:loadTranslationTable{
  ["moesp__zhangchangpu"] = "张昌蒲",
  ["designer:moesp__zhangchangpu"] = "北冰洋",
  ["#moesp__zhangchangpu"] = "矜严明训",

  ["emo__yanjiao"] = "严教",
  [":emo__yanjiao"] = "出牌阶段限一次，你可以选择一名角色并从牌堆顶亮出四张牌，该角色将这些牌分成点数之和相等的两组，你选择获得其中一组，若选择的角色不为你，该角色获得另一组牌，否则你须将另一组牌交给一名其他角色或置入弃牌堆。最后将剩余未分组的牌置于弃牌堆。若成功分组，你跳过本回合弃牌阶段。",
  ["Group1"] = "第一组",
  ["Group2"] = "第二组",
  ["#emo__yanjiao"]= "严教：对一名角色发动“严教”",
  ["@emo__yanjiao"] = "严教",
  ["#emo__yanjiao-choice"] = "严教：选择你获得的一组",
  ["#emo__yanjiao-choose"] = "严教：将另一组交给一名其他角色。点“取消”：弃置",

  ["emo__xingshen"] = "省身",
  [":emo__xingshen"] = "每当你受到1点伤害后，你可以摸两张牌且获得2个“省身”标记。你下一次发动〖严教〗时移除所有（至多6个）“省身”标记，增加等量张亮出的牌。",

  ["$emo__yanjiao1"] = "书卷精妙，需早学勤记。",
  ["$emo__yanjiao2"] = "幼时不学，弱冠智愚。",
  ["$emo__yanjiao3"] = "幼儿顽劣，需严加管教。",
  ["$emo__xingshen1"] = "清新省身，淡然虚静。",
  ["$emo__xingshen2"] = "三省吾身，方能知清寻源。",
  ["~moesp__zhangchangpu"] = "家事不宁，国事不安。",
}


local moesp__xuanwomingzi = General(extension, "moesp__xuanwomingzi", "moe", 4, 4, General.Female)

---@param room Room
local function getSeyouGenerals (room)
  local generals = room:getTag("emo__seyou_general")
  if generals == nil then
    generals = {}
    for _, g_name in ipairs(room.general_pile) do
      local g = Fk.generals[g_name]
      if g.gender == General.Female and table.find(g:getSkillNameList(), function(s) return MoeFunc.isPureSkill(s) end) then
        table.insert(generals, g_name)
      end
    end
    room:setTag("emo__seyou_general", generals)
  end
  local temp = table.simpleClone(generals)
  for _, p in ipairs(room.players) do
    table.removeOne(temp, p.general)
    if p.deputyGeneral ~= "" then
      table.removeOne(temp, p.deputyGeneral)
    end
  end
  return temp
end

local emo__seyou = fk.CreateTriggerSkill{
  name = "emo__seyou",
  events = { fk.RoundStart },
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local generals = getSeyouGenerals(room)
    if #generals == 0 then return end
    local general = table.random(generals)---@type string
    if player.deputyGeneral == "moesp__xuanwomingzi" then
      room:setDeputyGeneral(player, general)
    else
      room:setPlayerGeneral(player, general, true)
    end
    local skills = table.filter(Fk.generals[general]:getSkillNameList(), function(s)
      return MoeFunc.isPureSkill(s) and not player:hasSkill(s,true)
    end)
    if #skills > 0 then
      local old_skills = table.filter(player:getTableMark("emo__seyou_skill"), function(s) return player:hasSkill(s,true) end)
      if #old_skills < 3 then
        local new_skill = table.random(skills)
        table.insert(old_skills, new_skill)
        room:setPlayerMark(player, "emo__seyou_skill", old_skills)
        room:handleAddLoseSkills(player, new_skill)
      end
    end
    local targets = table.filter(room:getOtherPlayers(player), function (p)
      return not p:isNude() and (p.gender == General.Male or p.gender == General.Bigender)
    end)
    if #targets == 0 then return false end
    local to = table.random(targets)
    room:doIndicate(player.id, {to.id})
    room:moveCardTo(table.random(to:getCardIds("he"), 2), Card.PlayerHand, player, fk.ReasonPrey, self.name, nil, false, player.id)
  end,
}
moesp__xuanwomingzi:addSkill(emo__seyou)

local emo__huanshou = fk.CreateViewAsSkill{
  name = "emo__huanshou",
  pattern = "slash,jink",
  prompt = "#emo__huanshou-prompt",
  interaction = function()
    local names = {}
    if Fk.currentResponsePattern == nil and Self:canUse(Fk:cloneCard("slash")) then
      table.insertIfNeed(names, "slash")
    else
      for _, name in ipairs({"slash", "jink"}) do
        if Fk.currentResponsePattern and Exppattern:Parse(Fk.currentResponsePattern):match(Fk:cloneCard(name)) then
          table.insertIfNeed(names, name)
        end
      end
    end
    if #names == 0 then return end
    return UI.ComboBox {choices = names}
  end,
  card_filter = Util.FalseFunc,
  before_use = function (self, player, use)
    local room = player.room
    local skills = {}
    for _, s in ipairs(player.player_skills) do
      if s.visible and not (s:isEquipmentSkill(player) or s.name:endsWith("&")) then
        table.insert(skills, s.name)
      end
    end
    if #skills == 0 then return "" end
    local skill = room:askForChoice(player, skills, self.name, "#emo__huanshou-delete")
    room:handleAddLoseSkills(player, "-"..skill)
  end,
  after_use = function(self, player, use)
    local room = player.room
    local tos = {}
    if use.card.trueName == "slash" then
      tos = TargetGroup:getRealTargets(use.tos)
    elseif use.responseToEvent and use.responseToEvent.from then
      tos = {use.responseToEvent.from}
    end
    for _, pid in ipairs(tos) do
      if player.dead then break end
      local to = room:getPlayerById(pid)
      if not to:isNude() then
        local card = room:askForCardChosen(player, to, "he", self.name)
        room:throwCard(card, self.name, to, player)
      end
    end
  end,
  view_as = function(self)
    if self.interaction.data == nil then return end
    local card = Fk:cloneCard(self.interaction.data)
    card.skillName = self.name
    return card
  end,
  enabled_at_play = function(self, player)
    return table.find(player.player_skills, function (s)
      return s.visible and not (s:isEquipmentSkill(player) or s.name:endsWith("&"))
    end)
  end,
  enabled_at_response = function (self, player, response)
    return not response and table.find(player.player_skills, function (s)
      return s.visible and not (s:isEquipmentSkill(player) or s.name:endsWith("&"))
    end)
  end,
}

moesp__xuanwomingzi:addSkill(emo__huanshou)

Fk:loadTranslationTable{
  ["moesp__xuanwomingzi"] = "漩涡鸣子",
  ["designer:moesp__xuanwomingzi"] = "三娘鲍里真暖",
  
  ["emo__seyou"] = "色诱",
  [":emo__seyou"] = "锁定技，每轮开始时，你变形成随机女性武将，然后获得此武将随机一个无技能标签的技能（至多以此法拥有三个），然后获得随机一名男性角色的随机两张牌。",

  ["emo__huanshou"] = "幻兽",
  [":emo__huanshou"] = "你可以失去一个技能视为使用【杀】/【闪】，并弃置目标角色/响应角色一张牌。",
  ["#emo__huanshou-prompt"] = "幻兽：你可以失去一个技能视为使用【杀】/【闪】",
  ["#emo__huanshou-delete"] = "幻兽：选择要失去的技能",
}


local moesp__caojinyu = General(extension, "moesp__caojinyu", "moe", 3, 3, General.Female)
moesp__caojinyu.subkingdom = "wei"

local emo__xiushen = fk.CreateTriggerSkill{
  name = "emo__xiushen",
  mute = true,
  events = {fk.GameStart},
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name, math.random(2) + (event == fk.GameStart and 0 or 2))
    room:notifySkillInvoked(player, self.name)
    if room:askForChoice(player, {"emo__xiushen1","emo__xiushen2"}, self.name) == "emo__xiushen1" then
      room:addPlayerMark(player, "@emo__xiushen")
    else
      room:changeMaxHp(player, 1)
    end
  end,
}

local emo__xiushen_distance = fk.CreateDistanceSkill{
  name = "#emo__xiushen_distance",
  correct_func = function(self, from, to)
    if from:hasSkill(emo__xiushen) then
      return - from:getMark("@emo__xiushen")
    end
  end,
}
emo__xiushen:addRelatedSkill(emo__xiushen_distance)
moesp__caojinyu:addSkill(emo__xiushen)

local emo__yuyi = fk.CreateTriggerSkill{
  name = "emo__yuyi",
  events = {fk.Damaged},
  anim_type = "drawcard",
  can_trigger = function(self, event, target, player, data)
    return player:distanceTo(target) < 2 and not player:isRemoved() and not target:isRemoved() and not target.dead
    and player:hasSkill(self) and player:usedSkillTimes(self.name, Player.HistoryTurn) < 2
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    return room:askForSkillInvoke(player, self.name, nil, "#emo__yuyi-invoke:"..target.id)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = target.maxHp
    local y = #table.filter(room.alive_players, function(p) return player:distanceTo(p) > 1 end)
    local all_choices = {"emo__yuyi1::"..target.id..":"..x..":"..y, "emo__yuyi2::"..":"..x..":"..y, "emo__yuyi3"}
    local choices = table.simpleClone(all_choices)
    if target.dead then table.remove(choices, 1) end
    local choice = room:askForChoice(player, choices, self.name, nil, false, all_choices)
    if choice:startsWith("emo__yuyi1") then
      target:drawCards(x, self.name)
      if not target.dead and y > 0 then
        room:askForDiscard(target, y, y, true, self.name, false)
      end
    elseif choice:startsWith("emo__yuyi2") then
      player:drawCards(x, self.name)
      if not player.dead and y > 0 and not player:isNude() then
        local put = (#player:getCardIds("he") <= y) and player:getCardIds("he") or
        room:askForCard(player, y, y, true, self.name, false, ".", "#emo__yuyi-put:::"..y)
        if #put > 1 then
          put = room:askForGuanxing(player, put, nil, {0,0}, self.name, true).top
        end
        room:moveCards({
          ids = table.reverse(put),
          from = player.id,
          toArea = Card.DrawPile,
          moveReason = fk.ReasonPut,
          skillName = self.name,
          proposer = player.id,
        })
      end
    else
      room:loseHp(player, 1, self.name)
      if player.dead then return end
      local skill = Fk.skills["emo__xiushen"]
      room:useSkill(player, skill, function()
        return skill:use(fk.Damaged, player, player, {})
      end)
    end
  end,
}
moesp__caojinyu:addSkill(emo__yuyi)

Fk:loadTranslationTable{
  ["moesp__caojinyu"] = "金乡公主",
  ["designer:moesp__caojinyu"] = "喜欢我曹金玉吗",
  
  ["emo__xiushen"] = "修身",
  [":emo__xiushen"] = "锁定技，游戏开始时，你选择一项：1，你计算与其他角色的距离-1；2，增加一点体力上限。",
  ["emo__xiushen1"] = "计算与其他角色距离-1",
  ["emo__xiushen2"] = "增加一点体力上限",
  ["@emo__xiushen"] = "修身",

  ["emo__yuyi"] = "隅意",
  [":emo__yuyi"] = "每回合限两次，每当你距离1以内的角色受到伤害后，你可以选择一项：1，令其摸X张牌，然后弃置Y张牌；2，你摸X张牌，然后将Y张牌以任意顺序置于牌堆顶；3，你失去一点体力发动〖修身〗（X为其体力上限，Y为你计算距离大于1的角色数）。",
  ["#emo__yuyi-invoke"] = "隅意：可以对 %src 发动“隅意”",
  ["emo__yuyi1"] = "令 %dest 摸 %arg 张牌并弃置 %arg2 张牌",
  ["emo__yuyi2"] = "你摸 %arg 张牌，并将 %arg2 张牌置于牌堆顶",
  ["emo__yuyi3"] = "你失去一点体力发动〖修身〗",
  ["#emo__yuyi-put"] = "将 %arg 张牌置于牌堆顶",

  ["$emo__xiushen1"] = "善身循礼，天自怜之。",
  ["$emo__xiushen2"] = "此间乱，不忍以身入淤泥。",
  ["$emo__xiushen3"] = "颜娴人静，不为俗世所扰。",
  ["$emo__xiushen4"] = "世皆纷扰，唯我独静。",
  ["$emo__yuyi1"] = "隅角草木为盛，皆我泪沃之。",
  ["$emo__yuyi2"] = "胭脂败彩，以泪洗面。",
  ["~moesp__caojinyu"] = "何郎负我，我心伤悲。",
}

local moesp__liyuu = General(extension, "moesp__liyuu", "moe", 3, 4, General.Female)

---@param room Room
local getYugeeSkills = function (room)
  local skills = room:getTag("emo__yugee_skills")
  if skills == nil then
    skills = {}
    for name, card in pairs(Fk.all_card_types) do
      if not table.contains(room.disabled_packs, card.package.name) and not card.is_derived and card.equip_skill then
        if card.sub_type == 3 or card.sub_type == 4 or card.sub_type == Card.SubtypeTreasure then
          table.insert(skills, {card.equip_skill.name, name})
        end
      end
    end
    room:setTag("emo__yugee_skills", skills)
  end
  return skills
end

local emo__yugee = fk.CreateTriggerSkill{
  name = "emo__yugee",
  frequency = Skill.Compulsory,
  mute = true,
  events = {fk.CardUsing, fk.Damage, fk.Damaged},
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) then
      if event == fk.CardUsing then
        return data.card.type ~= Card.TypeEquip and #player:getTableMark("@$emo__yugee_equips") < 4
      else
        return #player:getTableMark("@$emo__yugee_equips") > 0
      end
    end
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    -- 哈哈，减少语音播放频率
    if player:usedSkillTimes(self.name, Player.HistoryGame) % 4 == 1 then
      player:broadcastSkillInvoke(self.name)
    end
    if event == fk.CardUsing then
      room:notifySkillInvoked(player, self.name, "special")
      local skillsMap = table.filter(getYugeeSkills(room), function(s) 
        return not player:hasSkill(s[1], true) 
      end)
      if #skillsMap > 0 then
        local map = table.random(skillsMap)
        
        local mark = player:getTableMark("@$emo__yugee_equips")
        table.insertIfNeed(mark, map[2])
        room:setPlayerMark(player, "@$emo__yugee_equips", mark)
        mark = player:getTableMark("emo__yugee_skills")
        table.insertIfNeed(mark, map[1])
        room:setPlayerMark(player, "emo__yugee_skills", mark)

        room:handleAddLoseSkills(player, map[1], nil, false, true)
      end
    else
      room:notifySkillInvoked(player, self.name, "drawcard")
      local mark = player:getTableMark("@$emo__yugee_equips")
      local equip_name = table.remove(mark, 1)
      room:setPlayerMark(player, "@$emo__yugee_equips", #mark > 0 and mark or 0)
      mark = player:getTableMark("emo__yugee_skills")
      local skill = table.remove(mark, 1)
      room:setPlayerMark(player, "emo__yugee_skills", mark)

      if not table.find(player:getCardIds("e"), function(id) 
        return Fk:getCardById(id).equip_skill and Fk:getCardById(id).equip_skill.name == skill 
      end) then
        room:handleAddLoseSkills(player, "-"..skill, nil, false, true)
      end
      local id = table.find(Fk:getAllCardIds(), function(id) return Fk:getCardById(id, true).name == equip_name 
      and not table.contains(player.player_cards[Player.Hand], id) end)
      if id then
        room:obtainCard(player, id, true, fk.ReasonPrey)
      end
      if not player.dead then
        player:drawCards(1, self.name)
      end
    end
  end,

  refresh_events = {fk.EventLoseSkill, fk.AfterCardsMove},
  can_refresh = function (self, event, target, player, data)
    if event == fk.EventLoseSkill then
      return target == player and data == self
    elseif player:hasSkill(self, true) then
      for _, move in ipairs(data) do
        if move.from == player.id then
          for _, info in ipairs(move.moveInfo) do
            if info.fromArea == Card.PlayerEquip then
              return true
            end
          end
        end
      end
    end
  end,
  on_refresh = function (self, event, target, player, data)
    local room = player.room
    if event == fk.EventLoseSkill then
      for _, skill in ipairs(player:getTableMark("emo__yugee_skills")) do
        room:handleAddLoseSkills(player, "-"..skill, nil, false, true)
      end
      room:setPlayerMark(player, "@$emo__yugee_equips", 0)
      room:setPlayerMark(player, "emo__yugee_skills", 0)
    else
      for _, skill in ipairs(player:getTableMark("emo__yugee_skills")) do
        if not player:hasSkill(skill, true) then
          room:handleAddLoseSkills(player, skill, nil, false, true)
        end
      end
    end
  end,
}
moesp__liyuu:addSkill(emo__yugee)

local emo__woshou = fk.CreateActiveSkill{
  name = "emo__woshou",
  mute = true,
  switch_skill_name = "emo__woshou",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryPhase) < (1 + player:getMark("emo__woshou_updata"))
  end,
  prompt = function (self)
    return "#emo__woshou-prompt"..Self:getSwitchSkillState(self.name)
  end,
  target_num = 1,
  card_num = 1,
  card_filter = function (self, to_select, selected)
    return #selected == 0
  end,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and Self.id ~= to_select and #selected_cards == 1
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local card = Fk:getCardById(effect.cards[1])
    local type, color = "emo__woshou_"..card:getTypeString(), card.color
    room:obtainCard(to, card, true, fk.ReasonGive, player.id)
    if to.dead then return end
    if player:getSwitchSkillState(self.name, true) == fk.SwitchYang then
      room:notifySkillInvoked(player, self.name, "support")
      player:broadcastSkillInvoke(self.name, math.random(2))
      if color == Card.Black then
        to:drawCards(2, self.name)
      elseif color == Card.Red and to:isWounded() then
        room:recover { num = 1, skillName = self.name, who = to, recoverBy = player }
      end
    else
      room:notifySkillInvoked(player, self.name, "control")
      player:broadcastSkillInvoke(self.name, 3)
      local mark = to:getTableMark("@emo__woshou")
      table.insertIfNeed(mark, type)
      room:setPlayerMark(to, "@emo__woshou", mark)
    end
  end
}
local emo__woshou_delay = fk.CreateTriggerSkill{
  name = "#emo__woshou_delay",
  mute = true,
  frequency = Skill.Compulsory,
  events = {fk.DamageCaused},
  can_trigger = function(self, event, target, player, data)
    return target == player and table.contains(player:getTableMark("@emo__woshou"), "emo__woshou_equip") 
  end,
  on_use = function(self, event, target, player, data)
    data.damage = data.damage - 1
  end,

  refresh_events = {fk.AfterTurnEnd},
  can_refresh = function (self, event, target, player, data)
    return target == player and player:getMark("@emo__woshou") ~= 0
  end,
  on_refresh = function (self, event, target, player, data)
    player.room:setPlayerMark(player, "@emo__woshou", 0)
  end,
}
emo__woshou:addRelatedSkill(emo__woshou_delay)

local emo__woshou_prohibit = fk.CreateProhibitSkill{
  name = "#emo__woshou_prohibit",
  is_prohibited = function(self, player, to, card)
    return table.contains(player:getTableMark("@emo__woshou"), "emo__woshou_basic")
    and player ~= to and card and card.color == Card.Black
  end,
}
emo__woshou:addRelatedSkill(emo__woshou_prohibit)

local emo__woshou_invalidity = fk.CreateInvaliditySkill {
  name = "#emo__woshou_invalidity",
  invalidity_func = function(self, player, skill)
    return table.contains(player:getTableMark("@emo__woshou"), "emo__woshou_trick")
    and not skill.name:endsWith("&") and not skill:isEquipmentSkill(player)
  end
}
emo__woshou:addRelatedSkill(emo__woshou_invalidity)

moesp__liyuu:addSkill(emo__woshou)

local emo__yanchang = fk.CreateTriggerSkill{
  name = "emo__yanchang",
  frequency = Skill.Limited,
  mute = true,
  events = {fk.AfterDying},
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
    and player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    player:broadcastSkillInvoke(self.name, 1)
    player.room:delay(1000)
    player:broadcastSkillInvoke(self.name, 2)
    player.room:notifySkillInvoked(player, self.name, "big")
    room:setPlayerMark(player, "emo__woshou_updata", 1)
    player:drawCards(math.min(5, #room.alive_players), self.name)
  end,
}
moesp__liyuu:addSkill(emo__yanchang)


Fk:loadTranslationTable{
  ["moesp__liyuu"] = "喻黎黎",
  ["#moesp__liyuu"] = "学园偶像",
  ["cv:moesp__liyuu"] = "Liyuu_",
	["illustrator:moesp__liyuu"] = "馒嘟",
  ["designer:moesp__liyuu"] = "ZEELSE", -- 其实是我 (＾－＾)V
  
  ["emo__yugee"] = "鱼歌",
  [":emo__yugee"] = "锁定技，每当你使用一张非装备牌时，你随机获得装备技能（至多以此法拥有四个）；每当你造成或受到伤害后，你须失去最早以此法获得的装备技能，获得一张对应的装备牌并摸一张牌。",
  ["@$emo__yugee_equips"] = "鱼歌",

  ["emo__woshou"] = "握手",
  [":emo__woshou"] = "转换技，出牌阶段限一次，你可以交给一名其他角色一张牌，阳：若此牌为红色，其回复一点体力，若为黑色，其摸两张牌；阴：根据此牌的类型，其获得效果直到其下回合结束：基本牌，无法对其他角色使用黑色牌；装备牌：造成伤害-1；锦囊牌：技能失效。",

  ["#emo__woshou_delay"] = "握手",
  ["#emo__woshou-prompt0"] = "交给其他角色一张牌，红色:其回复一点体力；黑色:其摸两张牌",
  ["#emo__woshou-prompt1"] = "交给其他角色一张牌，基本:无法用黑色牌；装备:造成伤害-1；锦囊:技能失效",
  ["@emo__woshou"] = "握手:",
  ["emo__woshou_basic"] = "禁黑",
  ["emo__woshou_equip"] = "减伤",
  ["emo__woshou_trick"] = "封技",

  ["emo__yanchang"] = "演唱",
  [":emo__yanchang"] = "限定技，当你脱离濒死状态时，你可以摸等于存活角色数的牌（至多摸五张），且〖握手〗改为每阶段限两次。",

  ["$emo__yugee1"] = "（歌声）",
  ["$emo__woshou1"] = "太好听了吧！",
  ["$emo__woshou2"] = "你唱歌真的好好听啊，简直就是天籁！",
  ["$emo__woshou3"] = "真爱！这是真爱啊！",
  ["$emo__yanchang1"] = "我们以后一起唱好不好？",
  ["$emo__yanchang2"] = "一起唱，一起做学园偶像！",
}

local moesp__maolei = General(extension, "moesp__maolei", "moe", 3, 3, General.Female)

local emo__ouxiang = fk.CreateViewAsSkill{
  name = "emo__ouxiang",
  pattern = ".|.|.|.|.|trick,basic",
  prompt = function(_, selected_cards)
    -- 计算总数和距离下个13的数
    local count, rest = 0, 0
    if type(selected_cards) == "table" then
      for _, cid in ipairs(selected_cards) do
        count = count + Fk:getCardById(cid).number
      end
      rest = 13 - (count % 13)
      rest = (rest + 1) % 13 -1
    end
    return "#emo__ouxiang-prompt:::"..count..":"..rest
  end,
  interaction = function(self)
    local all_names = U.getAllCardNames("bt")
    local mark = Self:getTableMark("@$emo__ouxiang_card")
    local names = table.filter(U.getViewAsCardNames(Self, self.name, all_names), function (name)
      return not table.contains(mark, Fk:cloneCard(name).trueName)
    end)
    if #names > 0 then
      return U.CardNameBox { choices = names, all_choices = all_names }
    end
  end,
  card_filter = function(self, to_select, selected)
    if #selected == 4 then return end
    local card = Fk:getCardById(to_select)
    if card.number == 0 or card.suit == Card.NoSuit then return false end
    return not table.find(selected, function(id) return Fk:getCardById(id).suit == card.suit end)
  end,
  view_as = function(self, cards)
    if #cards == 0 or #cards > 4 then return end
    if not self.interaction.data or table.contains(Self:getTableMark("@emo__ouxiang-turn"), #cards) then return end
    local n = 0
    for _, id in ipairs(cards) do
      n = n + Fk:getCardById(id).number
    end
    if n % 13 == 0 then
      local c = Fk:cloneCard(self.interaction.data)
      c.skillName = self.name
      c:addSubcards(cards)
      return c
    end
  end,
  before_use = function(self, player, use)
    local room = player.room
    local mark = player:getTableMark("@emo__ouxiang-turn")
    table.insert(mark, #use.card.subcards)
    table.sort(mark, function(a, b) return a < b end)
    room:setPlayerMark(player, "@emo__ouxiang-turn", mark)
    -- 可能有隐患，应该绑定信息在使用事件上，但是打出事件绑不进
    room:setCardMark(use.card, "emo__ouxiang_user", player.id)
    room:addTableMark(player, "@$emo__ouxiang_card", use.card.trueName)
  end,
  enabled_at_play = function(self, player)
    return not player:isNude() and #player:getTableMark("@emo__ouxiang-turn") < 4
  end,
  enabled_at_response = function (self, player, response)
    if not player:isNude() and #player:getTableMark("@emo__ouxiang-turn") < 4 then
      local mark = player:getTableMark("@$emo__ouxiang_card")
      local all_names = U.getAllCardNames("bt")
      return table.find(U.getViewAsCardNames(player, self.name, all_names), function (name)
        return not table.contains(mark, Fk:cloneCard(name).trueName)
      end)
    end
  end,
}

local emo__ouxiang_delay = fk.CreateTriggerSkill{
  name = "#emo__ouxiang_delay",
  events = {fk.CardUseFinished, fk.CardRespondFinished},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    return not player.dead and data.card:getMark("emo__ouxiang_user") == player.id
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local num = #data.card.subcards
    local ids = {}
    if num == 1 then
      local c = Fk:getCardById(data.card.subcards[1])
      ids = room:getCardsFromPileByRule(".|.|"..c:getSuitString(), 1)
    elseif num == 2 then
      local n = 0
      for _, id in ipairs(data.card.subcards) do
        n = math.max(n, Fk:getCardById(id).number)
      end
      ids = room:getCardsFromPileByRule(".|"..n, 2)
    elseif num == 3 then
      local list = {}
      local map = {}
      for _, id in ipairs(data.card.subcards) do
        table.insert(list, Fk:getCardById(id).suit)
      end
      for i = 1, 13 do
        map[i] = {}
      end
      for _, id in ipairs(room.draw_pile) do
        local c = Fk:getCardById(id)
        if map[c.number] then
          if #table.filter(list, function(t) return t == c.suit end) > #table.filter(map[c.number], function(t) return t[1] == c.suit end) then
            table.insert(map[c.number], {c.suit, id})
            if #map[c.number] == 3 then
              ids = table.map(map[c.number], function(t) return t[2] end)
              break
            end
          end
        end
      end
    elseif num == 4 then
      local list = {}
      local map = {}
      for _, id in ipairs(data.card.subcards) do
        table.insert(list, Fk:getCardById(id).number)
      end
      for i = 1, 4 do
        map[i] = {}
      end
      for _, id in ipairs(room.draw_pile) do
        local c = Fk:getCardById(id)
        if map[c.suit] then
          if #table.filter(list, function(t) return t == c.number end) > #table.filter(map[c.suit], function(t) return t[1] == c.number end) then
            table.insert(map[c.suit], {c.number, id})
            if #map[c.suit] == 4 then
              ids = table.map(map[c.suit], function(t) return t[2] end)
              break
            end
          end
        end
      end
    end
    if #ids == 0 then
      ids = MoeFunc.getShade(room, num)
    end
    if #ids > 0 then
      room:moveCardTo(ids, Player.Hand, player, fk.ReasonPrey, self.name)
    end
  end,
}
emo__ouxiang:addRelatedSkill(emo__ouxiang_delay)

moesp__maolei:addSkill(emo__ouxiang)

Fk:loadTranslationTable{
  ["moesp__maolei"] = "猫雷",
  ["#moesp__maolei"] = "NyaRu",
  ["designer:moesp__maolei"] = "水天一色",
  
  ["emo__ouxiang"] = "偶像",
  [":emo__ouxiang"] = "每回合每项限一次，每牌名限一次，你可以将至多四张花色均不同且点数和为13的倍数的牌当任意基本牌或普通锦囊牌使用或打出。此牌结算后，你执行第X项："..
  "<br>1.获得X张花色与你以此法转化牌相同的牌。"..
  "<br>2.获得X张点数等于你以此法转化牌中最大点数的牌。"..
  "<br>3.获得X张点数相同且与你以此法转化牌的花色对应相同的牌。"..
  "<br>4.获得X张花色相同且与你以此法转化牌的点数对应相同的牌。"..
  "<br>若没有符合的牌，你获得X张【影】（X为以此法转化的牌数）。",

  ["#emo__ouxiang-prompt"] = "偶像：选择花色均不同且点数和为13倍数的牌（当前点数：%arg，还差%arg2点！）",
  ["#emo__ouxiang_delay"] = "偶像",
  ["@emo__ouxiang-turn"] = "偶像:数",
  ["@$emo__ouxiang_card"] = "偶像:牌",
}

local moesp__caochong = General(extension, "moesp__caochong", "moe", 3)
moesp__caochong.subkingdom = "wei"

local emo__keai = fk.CreateTriggerSkill{
  name = "emo__keai",
  events = {fk.DamageInflicted},
  anim_type = "drawcard",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    return target == player and player:hasSkill(self)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local x = player:usedSkillTimes(self.name, Player.HistoryGame) + 1
    room:addPlayerMark(player, MarkEnum.AddMaxCardsInTurn, x)
    player:drawCards(x, self.name)
  end,
}
moesp__caochong:addSkill(emo__keai)

local emo__nanliang = fk.CreateActiveSkill{
  name = "emo__nanliang",
  anim_type = "control",
  card_num = 0,
  target_num = 1,
  card_filter = Util.FalseFunc,
  target_filter = function(self, to_select, selected, selected_cards)
    return #selected == 0 and not table.contains(Self:getTableMark("emo__nanliang-phase"), to_select)
  end,
  can_use = function(self, player)
    return table.find(Fk:currentRoom().alive_players, function (p)
      return not table.contains(player:getTableMark("emo__nanliang-phase"), p.id)
    end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    local to = room:getPlayerById(effect.tos[1])
    local mark = player:getTableMark("emo__nanliang-phase")
    table.insert(mark, to.id)
    room:setPlayerMark(player, "emo__nanliang-phase", mark)
    local choices = {}
    local card = Fk:cloneCard("duel")
    card.skillName = self.name
    if not to:prohibitUse(card) and not to:isProhibited(player, card) then
      table.insert(choices, "#emo__nanliang_duel:"..player.id)
    end
    if not to:isNude() then
      table.insert(choices, "#emo__nanliang_give:"..player.id)
    end
    if #choices == 0 then return end
    if room:askForChoice(to, choices, self.name):startsWith("#emo__nanliang_duel") then
      room:useVirtualCard("duel", nil, to, player, self.name, true)
    else
      local cards = room:askForCard(to, 1, 1, true, self.name, false, ".", "#emo__nanliang-card:"..player.id)
      if #cards > 0 then
        room:moveCardTo(cards, Player.Hand, player, fk.ReasonGive, self.name, nil, false, to.id)
        if not to.dead then
          to:turnOver()
        end
      end
    end
  end,
}
moesp__caochong:addSkill(emo__nanliang)

Fk:loadTranslationTable{
  ["moesp__caochong"] = "曹冲",
  ["designer:moesp__caochong"] = "冲儿可爱捏",--锊
  
  ["emo__keai"] = "可爱",
  [":emo__keai"] = "锁定技，当你受到伤害时，你摸X张牌，且你本回合手牌上限+X（X为本局游戏你发动此技能的次数+1）。",

  ["emo__nanliang"] = "南梁",
  [":emo__nanliang"] = "出牌阶段对每名角色限一次，你可以令一名角色选一项：1.视为对你使用一张【决斗】；2.交给你一张牌并翻面。",
  ["#emo__nanliang_duel"] = "视为对 %src 使用【决斗】",
  ["#emo__nanliang_give"] = "交给 %src 一张牌并翻面",
  ["#emo__nanliang-card"] = "南梁：请交给 %src 一张牌",
  ["#emo__nanliang-prompt"] = "南梁:令一名角色选择：视为对你使用一张【决斗】；或交给你一张牌并翻面",
}

local moesp__gilgamesh = General(extension, "moesp__gilgamesh", "god", 4, 4, General.Female)

local emo__tiansuo = fk.CreateActiveSkill{
  name = "emo__tiansuo",
  anim_type = "offensive",
  card_num = 0,
  min_target_num = 1,
  card_filter = Util.FalseFunc,
  prompt = "#emo__tiansuo-prompt",
  target_filter = function(self, to_select, selected)
    return to_select ~= Self.id and not table.contains(Self:getTableMark("emo__tiansuo_target"), to_select)
  end,
  can_use = function(self, player)
    return table.find(Fk:currentRoom().alive_players, function (p)
      return p ~= player and not table.contains(player:getTableMark("emo__tiansuo_target"), p.id)
    end)
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:sortPlayersByAction(effect.tos)
    local mark = player:getTableMark("emo__tiansuo_target")
    table.insertTable(mark, effect.tos)
    room:setPlayerMark(player, "emo__tiansuo_target", mark)
    for _, pid in ipairs(effect.tos) do
      local to = room:getPlayerById(pid)
      if not to.dead and not to.chained then
        to:setChainState(true)
      end
    end
    for _, pid in ipairs(effect.tos) do
      local to = room:getPlayerById(pid)
      if not to.dead then
        Fk.skills["emo__jinlv"]:use(nil, player, player, {to = to.id})
      end
    end
  end,
}
moesp__gilgamesh:addSkill(emo__tiansuo)

local emo__jinlv = fk.CreateTriggerSkill{
  name = "emo__jinlv",
  events = {fk.TargetSpecified},
  anim_type = "offensive",
  frequency = Skill.Compulsory,
  can_trigger = function(self, event, target, player, data)
    if target == player and player:hasSkill(self) and data.firstTarget and data.to ~= player.id
     and not table.contains(player:getTableMark("emo__jinlv_target-phase"), data.to) then
      local to = player.room:getPlayerById(data.to)
      return not to.dead and not to:isNude() and U.isOnlyTarget(to, data, event)
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askForSkillInvoke(player, self.name, nil, "#emo__jinlv-invoke:"..data.to)
  end,
  on_use = function(self, event, target, player, data)
    local room = player.room
    local to = room:getPlayerById(data.to)
    local mark = player:getTableMark("emo__jinlv_target-phase")
    table.insertIfNeed(mark, to.id)
    room:setPlayerMark(player, "emo__jinlv_target-phase", mark)
    if player.dead or to.dead then return end
    local cards = to:getCardIds("he")
    if #cards > 0 then
      local cardId = cards[1]
      if #cards > 1 then
        cardId = room:askForCard(to, 1, 1, true, self.name, false, ".", "#emo__jinlv-give:"..player.id)[1]
      end
      room:moveCardTo(cardId, Player.Hand, player, fk.ReasonGive, self.name, nil, true, to.id)
      if player.dead then return end
      local c = Fk:getCardById(cardId)
      if table.contains(player:getCardIds("h"), cardId) and U.getDefaultTargets(player, c, true, false) then
        local type = c.type
        U.askForUseRealCard(room, player, {cardId}, ".", self.name, "#emo__jinlv-use:::"..c:toLogString(), nil, false, false)
        if player.dead then return end
        if type == Card.TypeEquip then
          if not to:isNude() then
            local cid = room:askForCardChosen(player, to, "he", self.name, "#emo__jinlv-throw:"..to.id)
            room:throwCard({cid}, self.name, to, player)
          end
          if not player:isNude() and not to.dead then
            local give = room:askForCard(player, 1, 1, true, self.name, false, ".", "#emo__jinlv-back:"..to.id)
            room:moveCardTo(give, Player.Hand, to, fk.ReasonGive, self.name, nil, true, player.id)
          end
        elseif type == Card.TypeBasic then
          if not to.dead then
            local use = room:askForUseCard(to, "slash", "slash", "#emo__jinlv-slash:"..player.id, true,
            {bypass_distances = true,bypass_times = true, exclusive_targets = {player.id}})
            if use then
              room:useCard(use)
            else
              room:loseHp(to, 1, self.name)
            end
          end
        else
          MoeFunc.allDraw({player,to}, 1, self.name)
          if not to:isNude() then
            room:askForDiscard(to, 1, 1, true, self.name, false)
          end
        end
        return
      end
    end
    room:useVirtualCard("slash", nil, player, to, self.name, true)
  end,
}
moesp__gilgamesh:addSkill(emo__jinlv)

local emo__guaili = fk.CreateActiveSkill{
  name = "emo__guaili",
  anim_type = "offensive",
  frequency = Skill.Limited,
  card_num = 0,
  target_num = 0,
  card_filter = Util.FalseFunc,
  prompt = "#emo__guaili-prompt",
  can_use = function(self, player)
    return player:usedSkillTimes(self.name, Player.HistoryGame) == 0
  end,
  on_use = function(self, room, effect)
    local player = room:getPlayerById(effect.from)
    room:setPlayerMark(player, "@@emo__guaili-turn", 1)
    local n = 0
    for _, p in ipairs(room:getOtherPlayers(player)) do
      local slots = table.filter({Player.ArmorSlot, Player.DefensiveRideSlot, Player.TreasureSlot}, function (s)
        return table.contains(p:getAvailableEquipSlots(), s)
      end)
      for _, s in ipairs(slots) do
        if #p:getEquipments(Util.convertSubtypeAndEquipSlot(s)) > 0 then
          n = n + 1
        end
      end
      room:abortPlayerArea(p, slots)
    end
    if not player.dead then
      player:drawCards(n, self.name)
    end
  end,
}

local emo__guaili_delay = fk.CreateTriggerSkill{
  name = "#emo__guaili_delay",
  events = {fk.TurnEnd},
  mute = true,
  can_trigger = function(self, event, target, player, data)
    if player:getMark("@@emo__guaili-turn") > 0 then
      return #player.room.logic:getEventsOfScope(GameEvent.Death, 1, function(e)
        local death = e.data[1]
        return death.damage and death.damage.from == target
      end, Player.HistoryTurn) == 0
    end
  end,
  on_cost = Util.TrueFunc,
  on_use = function(self, event, target, player, data)
    local room = player.room
    room:abortPlayerArea(player, player:getAvailableEquipSlots())
    if player.hp > 0 then
      room:loseHp(player, player.hp, "emo__guaili")
    end
  end,
}
emo__guaili:addRelatedSkill(emo__guaili_delay)
moesp__gilgamesh:addSkill(emo__guaili)


Fk:loadTranslationTable{
  ["moesp__gilgamesh"] = "吉尔伽美什",
  ["#moesp__gilgamesh"] = "金闪闪",
  ["designer:moesp__gilgamesh"] = "祈",
  
  ["emo__tiansuo"] = "天锁",
  [":emo__tiansuo"] = "出牌阶段，你可以选择任意名未选择过的其他角色，横置这些角色，然后依次对这些角色发动一次〖金律〗。",
  ["#emo__tiansuo-prompt"] = "天锁:横置任意名角色(每角色限一次)，然后对这些角色发动〖金律〗",

  ["emo__jinlv"] = "金律",
  [":emo__jinlv"] = "每阶段对每名角色限一次，当你使用牌指定其他角色为唯一目标后，若该角色有牌，你可以令其交给你一张牌，若你无法使用此牌，你视为对其使用一张【杀】，否则你须使用此牌，然后若此牌的类型为：基本牌：其需对你使用一张【杀】，否则失去一点体力；装备牌：你弃置其一张牌，然后交给其一张牌；锦囊牌：你与其各摸一张牌，然后其弃置一张牌。",
  ["#emo__jinlv-invoke"] = "金律:你可以令 %src 交给你一张牌，并使用之(无法使用则视为对其使用杀)",
  ["#emo__jinlv-give"] = "金律:交给 %src 一张牌，若其不能使用此牌，其视为对你使用【杀】",
  ["#emo__jinlv-use"] = "金律：你须使用 %arg ！",
  ["#emo__jinlv-back"] = "金律：交给 %src 一张牌",
  ["#emo__jinlv-throw"] = "金律：弃置 %src 一张牌",
  ["#emo__jinlv-slash"] = "金律：你需对 %src 使用【杀】，否则失去一点体力",

  ["emo__guaili"] = "乖离",
  [":emo__guaili"] = "限定技，出牌阶段，你可以废除所有其他角色的所有防具、防御坐骑和宝具栏，然后摸X张牌（X为此装备栏内的牌数），本回合结束时，若你没有杀死角色，你废除所有装备栏并失去所有体力。",
  ["#emo__guaili-prompt"] = "乖离：废除所有其他角色的所有防具、防御坐骑和宝具栏，然后摸X张牌（X为此装备栏内的牌数）",
  ["@@emo__guaili-turn"] = "乖离发动",
  ["#emo__guaili_delay"] = "乖离",
}
















--[[

local moesp__xxxx = General(extension, "moesp__xxxx", "moe", 4, 4, General.Female)

Fk:loadTranslationTable{
  ["moesp__xxxx"] = "",
  ["designer:moesp__xxxx"] = "",
  
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",

  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
  [""] = "",
}

--]]











return extension

